Fetchmail & Pine



Any mail for me?

Getting your mail from a pop server is made pretty simple with fetchmail. This can be obtained either from your Linux CD or from the Web (http://www.tuxedo.org/~esr/fetchmail). With fetchmail, there are two complete ways to setup with /usr/bin/fetchmailconf. You can make it really easy by just setting up the Novice Configuration. Or, for more control (as well as more confusion), you could set up under the Expert Configuration. I'd found that fetchmail worked best when I set up both, but most of the confusion is displaced by the numerous Help buttons & some notation right on the screen.


And then there was pine.

Again, if you don't have it installed, & want to use it, either install from your CD, or download it from the Web: http://www.washington.edu/pine.

It's incredible, really. Some think of pine as a newbie mail reader (probably because it's so simple), but it does just about everything the usual readers do & though it requires actually entering fairly sophisticated options in Setup Config, it's not too difficult. Don't let any of this frighten you. It takes only a few minutes to get it up & running. Once you've got it working, you can go back & tweak the settings to your satisfaction.

The only thing you have to remember is if you'd set it up to connect directly to your pop server instead of your local mailbox folder on your pc, go in & remove what you'd typed in the Inbox-path line under Setup Config. Otherwise, naturally, you'll keep checking mail to find the mail box empty because fetchmail, sendmail & procmail have done their jobs, but pine is looking in the wrong place.


Notification

There are a couple of ways you can set up notification when mail arrives. If you have the KDE Internet utilities installed, there's something called kbiff (or just biff) get it either from your CD or from http://home.sprintmail.com/~granroth/kbiff. This too is simple to set up.

Though it's supposed to be able to use a wav file when it notifies, I've never been able to get that to work, so I opt for a system beep. I have since -- with the help of my friends -- found a way to use any wav file for notification. I'll add that info later.


Getting it all to work

Now, to get the whole thing started, you need to tell fetchmail to actually check your pop server for mail. For this you need to set up a cron (CD or from the Web, but I couldn't find their site) job. It should, though, have been included in your installation, as the system needs it.

By entering man crontab at a prompt ($ man crontab), the first sentence of importance tells us this:

"A crontab file contains instructions to the cron(8) daemon of the general form: 'run 
this command at this time on this date'."

As the name implies, cron runs applications at specific times. To set this up, you use crontab. At a prompt, enter crontab -e ($ crontab -e -- the -e is necessary to tell crontab that you want to edit your existing crontab -- if you don't have one yet, crontab creates one in your home directory).

There's a safer way to do it too: Either enter $touch crontab-temp or call it anything you'd like, then open the file in any text editor. Here you'll enter the info below:

#minute (0-59),
#| hour (0-23),
#| | day of the month (1-31),
#| | | month of the year (1-12),
#| | | | day of the week (0-6 with 0=Sunday).
#| | | | | commands
MAILTO="> /dev/null"

This info, apart from the last line, is simply so you remember what goes where. The last line is so that you won't get endless system e-mails telling you that cron is doing what you've set it up to do.

Opening crontab with the -e option will open it in the vi editor. As implied above, the vi editor is rather intimidating, but all one needs to know about it is the Insert command (i), delete line (dd), & the Save & Exit (Esc : x) commands. So, type crontab -e & open it up. It will likely be empty except for MAILTO=""^[ at the top followed by ~'s all the way down the page.

Pico, which comes with Pine is clean & simple -- don't let any ubergeek tell you otherwise.

My crontab, with the entry to check for mail on my pop server every ten minutes looks like this (I've removed most of the ~'s here for space):

MAILTO=""
1,10,20,30,40,50 * * * * /usr/bin/fetchmail -s > /dev/null 2&1
~
~
~
~
~
"/tmp/crontab.5044" 2 lines, 112 characters

Now, I'm hardly an expert at setting cron jobs (so, you might check out Nuintari's page for a better explanation: (http://www.erg-mad.com/linux/tricks/cron.shtml), but basically, it's composed of five asterisks, followed by the path to the application you want to run, then any options that application uses, & any other things you want to happen behind the scenes. So, for the first asterisk, I've entered those numbers separated by commas.

As this is the space concerning the minute interval, I've told crontab to run fetchmail at one minute, ten minutes, twenty minutes, etc, during the day. The other asterisks are for hour, day, month, & year. This example means that every ten (except for that first being nine) minutes of every hour of every day of every month of every year, cron will "wake up" fetchmail to check my server (of course, I'm connected to the internet via DSL, & a modem connection would need some other configuration -- hey, I've never connected a Linux box to the 'Net with an analogue modem, so I dunno, but check out Scott's Configuring Pine page -- he may get you connected). The final bit, -s tells fetcmail not to write to /var/log/messages (though it does anyway), > /dev/null 2&1 I don't fully understand, but that tells cron not to send an e-mail to the user who owns the cron job. Otherwise, cron would e-mail you every ten minutes that it's doing what you've asked.

After you enter the info, to save & exit (trust me, it took me a long time to find this), press your Esc key, then type a : (that's a full colon), type x & press Enter. If there's anything not set properly, like a mis-type or spaces between the commas, crontab will tell you.

But if you do it my way by creating a crontab-temp file with Pico, you'll find saving & exiting with Ctrl-x & typing y (for yes) to save, you'll find it easier. Then type: $ crontab crontab-temp (or whatever you've called the file), press Enter, & the data in your crontab-temp gets copied to your crontab file. Either way, if you've made any mistakes, you'll find a message on the command line telling you what's wrong.

In addition, you'll find that you're probably still getting mail from cron. Even if you don't, you'll do well to do something more. Open a terminal window, enter su, & type the root password (if you're not in X, ignore that, or if you've opened X after logging in as root, just open the terminal window), type pico /etc/crontab & press Enter. The crontab you've just opened is the system crontab & you'll probably find that there's a line near the top reading MAILTO=""^[. Remove the ^[ from it, hold your CTRL key & press x to save & close. Pico will ask if you want to save, press y & then Enter to save with the name crontab. You're done.

I've been told that there's a security issue with this /etc/crontab & that it may be best to delete it & any other crontab on the system but one. The one you keep could be /root/crontab or /home/your-user-name/crontab. If you choose to save the one in a user space, remember that some jobs may require super user permissions & you should decide appropriately. I live dangerously, leave the one in /etc, create one for me & another for root. I'm used to being called stupid, but you may not be. So think about what you really wanna do.

Now, the easy way: Copy any existing crontab file you can find on your system to your home directoy with a name like "crontab-bak", or anything you like. Open that one in pico, edit it to only show what you want -- keeping the info at the top, of course -- your fetchmail job, etc. Then, save & close it &, at the prompt, enter "crontab crontab-bak" ($ crontab crontab-bak ). Much, much easier. And you get to fool with your cron jobs witout fooling with emacs all the time.

Fetchmail can be set up manually too. Create a file called .fetchmailrc (touch .fetchmailrc -- don't forget the . at the beginning, or type pico .fetchmailrc & hit Enter). Now, open the newly made .fetchmailrc & enter this:

# Simple configuration file for fetchmail, runs as a daemon every 600th second,
# uses procmail for sorting of e-mails.
set logfile "/home/yourusername/mail/fetchmail-log"
set postmaster "yourusername"
set bouncemail
set properties ""
#set daemon 600

poll mail.isp.net with proto POP3
       user "yourispusername" there with password "xxxxxxxx" is yourusername here
options stripcr warnings 3600

poll mail.anotherisp.com with proto POP3
       user "yourispusername" there with password "xxxxxxxx" is yourusername here
options stripcr warnings 3600

poll pop.gmail.com with proto POP3
       user "gmailusername@gmail.com" there with password "xxxxxxxx" is yourusername here
options stripcr warnings 3600 ssl

First, the block at the top is what gets entered in the file by fetchmail when you use the fetchmail configurator. I keep it, as some of the info is necessary for fetchmail: The first two lines just tell you what the file is & what it does, the set logfile line tells fetchmail where to log what it does when. You can really put this file in any location you have access to as a user. I just happen to put it in my Pine mail directory. You can ignore the last three lines, put them in for fetchmail, but they really don't concern us.

Now we have the parts to tell fetchmail how & where to get your mail. In the first two cases, you can either tell fetchmail to get your mail from your mail server(s) by name or ip address. Because isp's sometimes change ip address round, it can be considered better to have fetchmail access your mail by server name (mail.someisp.com, pop.anotherisp.net, etc), but so long as you understand this, there's a very good reason I use ip addresses, whenever possible: Sometimes you'll find your isp's name servers are down. In my experience, this happens far too often, while I've never known an isp to actually change the ip address of their mail servers. So, choose as you feel best suits you.

Anyway, whether fetchmail is accessing via ip or name, it has to know what protocol to use. Normally, this is via POP3, but sometimes may be smtp, or imap or http. Don't worry about what any of those mean. Just know that each server will do things differently depending on the protocol, so ask your isp's tech support to verify which one is right for you. Then you enter the username for the account in question, the password used with that account which is likely different from the username & password you use on your home 'puter, followed by the username you use for your home 'puter. You may also ignore, but enter, the last line.

In the last example, I have the data for accessing an account you might have with GMail. Things have changed since I was accessing GMail with fetchmail, so you may have to play with these lines. I'll update this when I get my Linux box connected to the Net again. If it works, I'll take this disclaimer out. Otherwise, I'll figure out how to do it under Google's new access policy.


My general page
My personal home page
Me, Myself, & the Voices in my Head



Copyright 2004-2006