Search:  
Gentoo Wiki

Getmail

Contents

About

getmail is a mail retriever designed to allow you to get your mail from one or more mail accounts on various mail servers to your local machine for reading with a minimum of fuss. It is designed to be secure, flexible, reliable, and easy-to-use.

Install

We need net-mail/getmail.

Code: Install getmail
emerge -av getmail

Pre-Configure

We will save all getmail related files in ~/.getmail/.

Code:
mkdir ~/.getmail
chmod 0700 ~/.getmail

If you have only one mail account, we will create the file ~/.getmail/getmailrc.

Code:
touch ~/.getmail/getmailrc

If you have multiple mail accounts, we will need to create a configuration file for each of them.

Code:
touch ~/.getmail/getmailrc0
touch ~/.getmail/getmailrc1
touch ~/.getmail/getmailrc2
touch ~/.getmail/getmailrc3
touch ~/.getmail/getmailrc4

Configure

Now that you have created all getmail configuration files, we can begin to setup the mail accounts. A configuration file consists of three sections: retriever, destination and options. The section retriever contains your connection data to your mail provider. The destination section says what to happen with new mails like saving to disk. options contain settings such as being verbose, only check new mails, delete mails after having fetched them, logging messages to syslog, etc.

Retriever

IMAP

You can receive your Gmail mails using getmail. IMAP makes it even possible to receive your Spam mails. That's useful if you want to use your own spam-filter as the Gmail spam-filters recognize many ham-mails as spam. Note that you can only receive your spam-mails using IMAP. Gmail does not have an option to allow you to receive your spam-mails using POP3. If you've signed up your Gmail account from a German IP address, you need to substitute [Gmail]/Spam by [Google Mail]/Spam in the mailboxes variable (Google does not own the trademark Gmail in Germany, it is called there Google Mail instead. See Wikipedia for futher information.).

Code:
[retriever]
type = SimpleIMAPSSLRetriever
server = imap.gmail.com
username = <username>
password = <password>
mailboxes = ("INBOX", "[Google Mail]/Spam")

Use SimpleIMAPRetriever for the variable type if your server does not support SSL encryption.

POP3

Code:
[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmx.net
port = 110
username = <username>
password = <password>

Use SimplePOP3Retriever for the variable type if your server does not support SSL encryption.

Destination

getmail supports to directly save the files to the file system and to pipe it to other applications. The last one might be interesting for you if you want to check the incoming mails for spam or to move mails to subfolders according to their subjects, senders, etc. This can be done using the application procmail.

maildir

If you do not want to virus-check, auto-move or spam-check your incoming mails, you can use this method.

Code:
[destination]
type = Maildir
path = ~/.maildir/

If there is a new e-mail, it will be now in ~/.maildir mailbox and automatically made accessible via IMAP if desired.

procmail

Code:
[destination]
type = MDA_external
path = /usr/bin/procmail
arguments = ("-f", "%(sender)")

maildrop

Code:
[destination]  
type = MDA_external  
path = /usr/bin/maildrop  
unixfrom = true

Filter

SpamAssassin

Code:
[filter]  
type = Filter_external  
path = /usr/bin/spamc 

Options

Deleting mails after Fetching them

This can be either done globally using the getmail option -d or for every getmailrc-file manually (see next section for how to use the getmail-command) by setting delete to true in the section options:

Code:
[options]
delete = true

Enable verbosity

Code:
[options]
verbose = 1

Log messages to syslog instead of stdout

Code:
[options]
message_log_syslog = true

Specify log file

Instead of logging to syslog, you can specify the path to your own log file.

Code:
[options]
message_log = ~/.getmail/log

Run

Single-account setup

You can simply run getmail like this:

Code:
getmail

Multiple-account setup

You need to pass all getmailrc* files to the getmail command:

Code:
getmail --rcfile getmailrc0 --rcfile getmailrc1 --rcfile getmailrc2

Retrieving your mails automatically with cron

Once you are confident with your getmail setup, you can automate the fetching using a cron job. Open up your crontab (using crontab -e) and add the following:

File: crontab
# entry to fetch email every 5 minutes
*/5 * * * * getmail <parameters>

See also

Retrieved from "http://www.gentoo-wiki.info/Getmail"

Last modified: Sat, 06 Sep 2008 15:22:00 +0000 Hits: 13,206