/printerclub

Primary LanguageShellMIT LicenseMIT

printerclub

What if pen pals, but a little more modern? Printerclub is a simple bash script designed for Raspberry Pi that makes it easy for your friends to send messages that are printed directly on your printer. Sort of like a fax machine, but no phone line needed.

Requirements

  • A Raspberry Pi (or similar linux server) that is always running (macOS or Windows/WSL support will be added if there is sufficient interest)
  • A printer, either connected to the Raspberry Pi or on the same local network. The printer must be supported by CUPS (most are these days)
  • A Gmail or other email account used to receive messages
  • One or more friends to send you messages

How it Works

Printerclub is a bash script that checks your email account for new messages that meet certain conditions (by default emails with the word "printme" in the subject line). Set up to run periodically, it will download new messages, extract the attachments, then print the attachments on your printer. That's it!

Setup

First, clone the repo to your location of choice. For purposes of this README, I'll assume you clone it to ~/code/printerclub.

cd ~/code
git clone https://github.com/yesezra/printerclub

Before configuring the Printerclub script, you'll need to install three prerequsites on your Raspberry Pi: the CUPS printer system, getmail mail retriever, and mu.

sudo apt install cups getmail maildir-utils

Next, ensure that your printer is configured on your Raspberry Pi. Here's a thorough guide. If you don't have a GUI on your Pi, I highly recommend following the steps to enable the CUPS web interface at localhost:631 and configuring your printer from there. Note that if you are trying to use this interface from outside your Pi, you'll need to replace Listen localhost:631 with Port 631 in /etc/cups/cupsd.conf, as well as adding an Allow @local directive in each <Location> section. Again, follow the steps at the link.

If you have more than one printer installed, set a default printer. First, use this command to get a list of all installed printers:

lpstat -p -d

Then, set the default printer

lpoptions -d [printer]

Once configured, test your configuration by printing an image or pdf from the command line:

lp [insert any sample image or pdf here]

Now, we'll configure getmail. First, create getmail's required config directory:

mkdir ~/.getmail
chmod 700 ~/.getmail

Then, copy the the example getmailrc to the directory you just created:

cp ~/code/printerclub/getmailrc.example ~/.getmail/getmailrc__

At this point, you'll need to edit your getmailrc to your email account's server address, username, and password for your email account. The example uses the IMAP interface to Gmail. If you don't already have IMAP enabled, you'll need to do so in your Gmail settings > Forwarding and POP/IMAP > Enable IMAP.

Note: For security purposes, you should create an App Password for your Google account and use it instead of your account's full password. Follow these steps to set one up.

By default, getmail is configured to download messages with the "printme" label in Gmail. This is a good time to create that label in your Gmail account. I recommend creating a filter that automatically adds the printme label to emails with subjects that include "printme". I also recommend that these emails skip the inbox, so you get a nice surprise in your printer.

Gmail search showing a match for subject includes printme Gmail filter config showing skip inbox and autoapply label

Getmail offers many options so if the defaults don't work, review the docs and edit your config as needed. The only critical option is to store messages in the Maildir format (type = Maildir) and in the proper location (path = ~/.printerclub/Maildir/).

To confirm that getmail is configured properly, run it from the command line. Ensure a message has the printme label so there's a message to pull down!

getmail

If you see no errors, you should be ready to test the script! Run printerclub.sh:

chmod u+x ~/code/printerclub/printerclub.sh #make the script executable!
~/code/printerclub/printerclub.sh

At this point, you can configure cron to run the script automatically:

crontab -u pi -e #replace "pi" with your Raspberry Pi user account

You may need to select an editor if you don't have one set. You'll want to add the following line to the bottom of the file, then save and exit the editor.

*/15 * * * * /home/pi/code/printerclub/printerclub.sh

This will run the script every 15 minutes, but you can use normal cron syntax to change this if you like.

Finally, the script is installed and configured – the last step is to tell your friends to send you messages!

Uninstalling

rm -rf ~/.printerclub
rm -rf ~/.getmail
crontab -e -u pi #then remove crontab entry for printerclub and save