Debian and a few others are still using getmail 3.x so I am leaving this page up as a legacy page. For getmail 4.x, check out my main getmail page.
This article is very much of a howto as opposed to a Why to. I'm giving the quickstart guide for the impatient.
I'm not sure if the main docs for getmail 3 are still available. At present, it's still available at the author's site but I don't know if the docs are included in the tarballs.
In some distributions, you may have to install it yourself. The instructions for 3.x as I said, while no longer on the site should be included with the tarball but I'll give the gist here. (For this example, I'm using version 3.2.4, the last version of 3.x that I used.)
I should point out that if your distribution doesn't include it as a package of version 3.x you are probably better off using version 4.x. For more detailed information on 4.x see my main getmail page.
At any rate, if you are installing version 3.x from source (if you are using version 4.x go to my other page, for this procedure has also changed between versions 3 and 4)
| tar -zxvf getmail*tar.gz mkdir /usr/lib/getmail cp -a getmail-3.2.4/* /usr/lib/getmail/ cp getmail-3.2.4/getmail /usr/bin/ chmod 755 /usr/bin/getmail |
Putting the files in the abovementioned places cuts down on your editing as this is what getmail will use by default.
Although FreeBSD and Gentoo will track dependencies, in other Configuration is fairly simple. In FreeBSD, once it's installed, you'll see that you have a /usr/local/share/examples/getmail/getmailrc-example file. I just copied this over to my home directory.
| cp /usr/local/share/examples/getmail/getmailrc-example ~ |
(The ~ indicates that I'm copying it to my home directory).
One then creates a .getmail directory in their home directory and puts the getmailrc file in there. Like a .fetchmailrc, the permissions should be no higher than 0710.
| mkdir .getmail cp ~/getmailrc-examples .getmail/getmailrc chmod 0710 .getmail/getmailrc |
Now, we edit the getmailrc file. Say the user name is john, he's already set up his maildrop, as explained in my mutt article so he wants to use maildrop as his MDA (mail delivery agent). Maildrop is what I use, so this file is set accordingly--however, one could change maildrop to procmail without problem.
His ISP's pop server is pserver.isp.com, his user name, as stated, is john, and his password is 1234. So, he will open up the getmailrc file and see:
[default] # This section provides default arguments and values,
# and variables which can be used in other sections
verbose = 1 # Be verbose by default
readall = 0 # Retrieve only new messages by default
delete = 1 # Delete mail after retrieval by default
message_log = /var/log/getmail.log # Log message retrieval and delivery to this file by default
timeout = 240 # TCP timeout value; increase if on a poor connection or
# slow POP3 server. getmail defaults to a 180 second timeout.
max_message_size = 1048576 # Don't retrieve messages over 1MB (MiB). Default is 0, which
# means no limit.
[Joe's Mail] # Simple configuration for a single-user POP3 mailbox
server = mail.isp.com
port = 8110
username = joeuser
# no password specified; prompt for it when getmail is run
use_apop = 1 # Use APOP authentication for this account instead of
# cleartext PASS
postmaster = ~joeuser/Mail/default/ # Default delivery to this Maildir
message_log = "" # Don't log for this account
# No "local" directives necessary.
recipient_header = received # For this account, only look for recipient headers
recipient_header = x-envelope-to # in "Received:" and "X-Envelope-To:" headers
no_delivered_to = 1 # Don't add a Delivered-To: header for this mailbox
no_received = 1 # Don't add a Received: header for this mailbox
[Company Maildrop] # Multidrop or domain mailbox configuration
server = mail.isp.net
username = getmailinc
password = "password with trailing spaces "
delete = 0 # Don't delete messages immediately after retrieval
delete_after = 10 # Instead, delete them 10 days after first retrieving them
postmaster = /var/spool/mail/postmaster # mbox default destination if none of the "local" directives
# match
# Use regular expression matching on the following addresses
local = ^user1@isp.net$,~user1/Maildir/ # Mail for "user1@isp.net" is delivered to ~user1/Maildir/
local = ^user2@isp.net$,~user2/mbox # Mail for "user2@isp.net" is delivered to ~user1/mbox
local = ^user3-list@isp.net$,~user3/Mail/list # Handle this qmail-style extension address separately.
local = "^user3@isp.net$,|/usr/bin/maildrop -a" # Deliver mail for "user3@isp.net" to /usr/bin/maildrop for
# further processing
|
For the single user, we're only going to pay attention to the first two sections.
[default] # This section provides default arguments and values,
# and variables which can be used in other sections
verbose = 1 # Be verbose by default
readall = 0 # Retrieve only new messages by default
delete = 1 # Delete mail after retrieval by default
message_log = /var/log/getmail.log # Log message retrieval and delivery to this file by default
timeout = 240 # TCP timeout value; increase if on a poor connection or
# slow POP3 server. getmail defaults to a 180 second timeout.
max_message_size = 1048576 # Don't retrieve messages over 1MB (MiB). Default is 0, which
# means no limit.
[Joe's Mail] # Simple configuration for a single-user POP3 mailbox
server = mail.isp.com
port = 8110
username = joeuser
# no password specified; prompt for it when getmail is run
use_apop = 1 # Use APOP authentication for this account instead of
# cleartext PASS
postmaster = ~joeuser/Mail/default/ # Default delivery to this Maildir
message_log = "" # Don't log for this account
# No "local" directives necessary.
recipient_header = received # For this account, only look for recipient headers
recipient_header = x-envelope-to # in "Received:" and "X-Envelope-To:" headers
no_delivered_to = 1 # Don't add a Delivered-To: header for this mailbox
no_received = 1 # Don't add a Received: header for this mailbox
The first section is, obviously, the default values. 0 is false, 1 is true. If you leave the log value as is, then you'll have to create a file /var/log/getmail.log. As I didn't really need it, I changed its value to "" which means it won't get logged. Aside from that, I left things at their default value. The values are explained in the comments section.
Next we go to Joe's Mail. I changed the name to My Mail--one can call it what they want. Now come the values that have to be changed.
For our user john with password 1234 and an ISP popserver of pserver.isp.com we will change the values to the following.
| server = pserver.isp.com port = 110 username = john password = 1234 postmaster = "|/usr/local/bin/maildrop 2>&1" |
I then left the rest of the defaults as they were and deleted the rest of the example file.
If one needs to log for troubleshooting or other reasons, put the log in the user's home directory. For example, in the configuration above, one could add
| message_log= /home/john/getmail.log |
One can now simply type
| getmail |
at a command prompt, and it will fetch mail in a similar manner to fetchmail. One nice thing about it--if one uses fetchmail without also using sendmail, postfix or another heavy duty agent, one receives error messages although mail is retrieved. Using getmail gives no such errors. Although the error messages are harmless, they do annoy some people.
One can also bind the shift+G key in mutt to invoke it. In your .muttrc add
| macro index G"!getmail\n" "Invoke getmail" macro pager G"!getmail\n" "Invoke getmail" |
One minor gotcha, covered on getmail's page is that if there is some sort of error, getmail won't fetch the mail. For instance, I used the excellent despammed.com to help cut down on spam. However, this means that every email received at the despammed address will have [despammed] in the subject line which can be a nuisance, especially when trying to keep threads intact on a mailing list. When I was using procmail, my first procmail rule filtered it out with
| :0 f * ^Subject.*\[despammed\] | sed -e '/^Subject:.*\[despammed\]/s/\[despammed\] //g' |
The problem is that if something comes to another of my address, procmail's skipping of the [despammed] is considered an error and is written to stderr. If an external command (and procmail would be considered such, as it's not part of getmail) writes to stderr, getmail will consider the delivery a failure, and won't get the mail for you. If you know that your MDA might write to stderr even though the delivery is successful (as per the example above--procmail is writing to stderr but has no problem getting the mail and putting it in the proper mailbox) then you can fix it in your getmailrc by supplying a --quiet option if your MDA supoprts it or redirecting the stderr, which is what I do. That is why the line directing getmail to use procmail as the postmaster reads
| postmaster = "|/usr/local/bin/procmail 2>&1" |
If I don't do this, then getmail won't retrieve messages that aren't addressed to despammed.com.
A few other minor configuration issues--if your password has any non alpha-numeric characters--for example, if you used a password like p!#swd you may have to doublequote it in your getmailrc, eg
| password = "p!#swd" |
Also, any option value that contains a percent sign (%) has to
be escaped with another percent sign. For example, if your user
name is
| john%isp.com |
you would enter it in as
| john%%isp.com |
In general, I like to have getmail running in the background, checking for mail every ten minutes. With fetchmail, one does this with the -d option, making it run as daemon. However, getmail doesn't have this option--while some people write a script to do it, I follow the web page's advice, and run it as cronjob. For the newcomer unfamiliar with cron, it's used to run a job at regular intervals. There are six fields, minutes, hour, day of month, month, day of week and the actual job itself. In this case, I want getmail to run every ten minutes, regardless of the hour, day, etc. Therefore, the only fields specified are minutes and the actual job. This isn't a page about cron, so I'll simply give the procedure to have getmail poll the pop server every ten minutes.
Again, we'll have a user named john. We'll assume that you're new to this (otherwise, you probably wouldn't be reading it) and haven't given john a crontab or any specific jobs. So, as user john
| crontab -e |
The e means you're going to edit the crontab, You'll probably get an empty editor. In my case, vi is my default editor, so vi opens. For getmail to check for mail every 10 minutes, I would put
| */10 * * * * /usr/local/bin/getmail |
The first */10 refers to the minutes field, in this case, saying it will be run every 10 minutes. The next 4 asterisks refer to hours, day of month, etc, fields which I am not specifying.
However, in my particular situation, I may want to receive mail on a different computer. So, sometimes I have to stop this cronjob. It's quite easy
| crontab -r |
This removes the cron job. However, suppose that john wants getmail to check mail overnight, then stop it when he goes to work, then turn it on again when he gets home. Having to rewrite the cronjob could be a nuisance. So he can just save it as a text file
| crontab -l > cron.txt |
The l stands for list. The > redirects the output to a new file called cron.txt. Now, when he gets home, he wants to start the job again. So, once again
| crontab -e |
Once again, this will open the default editor. He can then simply copy the cron.txt file with whatever method his favorite editor uses. For instance, if he were using vi, and the cron.txt is in his home directory
| :r ~/cron.txt |
and the cron job is reinstated.
The above is really for example. In reality, the simplest way to do this would be to use crontab -e and simply comment out the getmail line with a #. Then, when user john wants to have the cronjob start running again, he can once again do the crontab -e and remove the #.
One quick note of warning. If you wanted the job to run every two hours and made a crontab like this
* */2 * * * |
it would be running every minute. The correct way to specify the job to run every two hours would be
0 */2 * * * |
If you have sendmail or some others running, then cron will email you frequently. Err, very frequently, like each time getmail grabs your mail. So, in that case, you might want to have your crontab read
| */10 * * * * /usr/local/bin/getmail >/dev/null 2>&1 |
(One glitch that I have lately noticed on FreeBSD 5.x is that sometimes the cronjob won't run, or the user will get a message from cron that permission was denied. This is covered on the getmail home page, it has to do with relatively short $PATH of cron. At any rate, the way to fix it is to, as root or with root privilege, use a text editor to open /usr/local/bin/getmail. In there you will notice a line that ends with
`which python` |
Change that part to read the full path to python. In FreeBSD it's in /usr/local/bin so you would change that to
"/usr/local/bin/python" |
I like getmail. As this page hopefully shows, it's not overly difficult to set up for the average home user. Although making a cronjob might seem a nuisance at first, it's quite easy. If you only receive mail on the one computer, you don't have to worry about removing and reinstating it which makes it even easier. Even if you do have to remove and replace it, it only takes a few seconds.
Fetchmail has had various vulnerabilities. Getmail is a nice alternative