On Thursday 30 April 2009 12:22:17 Michael Steinbeck-Reeves wrote:
Message: 1 Date: Thu, 30 Apr 2009 00:27:46 +0200 From: Andreas Ntaflos <daff@dword.org> Subject: Re: [Dovecot] How do I get my mail from fetchmail into dovecot?
I have dovecot (with squirrel mail etc.) running without any problems but cannot understand how to get e-mail from a pop server into dovecot. I have fetchmail configured to pick up the mail from the pop3 server but don't understand how to get it from there into my dovecot mbox structure.
My advice: forget Fetchmail and use Getmail [1] instead. Getmail does everything Fetchmail does, only better. The documentation is excellent, the author (and mailinglist) very responsive should you run into problems you can't seem to solve on your own and I believe there exist a number of HOWTOs on how to setup Getmail with Dovecot. Not that it's very difficult, though.
Thanks, I have changed over and your diagrams made it much more obvious what is actually going on.
I myself have such a "mail hamster" setup running just fine, which I mentioned a few weeks ago on this list [2]. You might find that post helpful.
The general idea is to use Getmail to poll the remote mail servers (I poll two POP servers and three IMAP-SSL servers), retrieve messages, optionally scan them for viruses and spam and then hand them over to your local Dovecot server using Dovecot's LDA "deliver". See [3] for a nice picture :) If you skip virus and spam scanning the configuration for a single remote IMAP server boils down to:
~/.getmail/remote_imap_server.rc:
[options] verbose = 0 read_all = false
[retriever] type = SimpleIMAPSSLRetriever server = address_of_remote_imap_server username = username_on_remote_server password = password_on_remote_server
[destination] type = MDA_external path = /usr/local/libexec/dovecot/deliver
The destination part tells getmail to call the "deliver" program (without any commandline options) with the retrieved message. Dovecot then does the rest.
That seems simple - thanks.
Do I just put a list of retrievers, one after the other with a single destination following that and let dovecot sort out the destinations?
Normally you have one RC file per remote server your want to poll, with each RC file looking quite like the example I gave. Create a cron job for Getmail to run periodically and tell it which RC files to use:
# Run every two minutes and get mail from the specified servers
*/2 * * * * /usr/bin/getmail \
--rcfile /home/daff/.getmail/dword.org.rc
--rcfile /home/daff/.getmail/gmx.at.rc
[...]
Refer to the Getmail docs for further info.
The only thing I don't understand and can't find/understand in the documentation is how to tell the LDA where to put my e-mails. I have mails to several addresses mixed up in several POP3 boxes and need to sort them out and deliver them based on the target address. e.g. michael@domain1 and michael@domain2 go to my box etc. I can't see where I identify the addresses and allocate the appropriate storage area.
This is where Sieve shines. If you don't use Sieve then the LDA (deliver) will just put any messages handed to it by Getmail into your top-level INBOX. With Sieve you can specify rules and tell the LDA what to do with each message. You should read up on Sieve [1], Sieve in Dovecot [2] and Dovecot's LDA [3]. Once you configured the LDA to understand Sieve you can create rules like the following:
~/.dovecot.sieve:
# Messages from the Dovecot list end up in the IMAP folder # INBOX.dword.dovecot-users if header :contains ["List-Id"] ["Dovecot Mailing List <dovecot.dovecot.org>"] { fileinto "INBOX.dword.dovecot-users"; stop; }
# All messages addressed directly to me shall end up in
# the IMAP folder INBOX.dword
if header :matches ["to","cc","bcc"]
["*daff@dword.org*"]
{
fileinto "INBOX.dword";
stop;
}
# Another account I have. Put those messages in # the IMAP folder INBOX.gmx. if address :contains ["to","cc","bcc"] ["my.address@gmx.at"] { fileinto "INBOX.gmx"; stop; }
Dovecot's Sieve support is excellent, thanks to Stephan Bosch. There is much more documentation out there than I can possibly provide or link to in this post but I think it gets the point across.
Hope this helps :)
Andreas
[1] http://sieve.info/ [2] http://wiki.dovecot.org/LDA/Sieve [3] http://wiki.dovecot.org/LDA
Andreas Ntaflos Vienna, Austria
GPG Fingerprint: 6234 2E8E 5C81 C6CB E5EC 7E65 397C E2A8 090C A9B4