fetchmail: Collecting Mail from the Provider

Support knowledgebase (fetchmail)

Question:

How can I collect mail from a POP3 mail server and distribute it on the local mail server?

Solution:

This can be done by means of the program fetchmail (package pop, series n).
(from SuSE Linux 6.3 on: package fetchml, series n; from SuSE Linux 7.1 on: package fetchmail)

The advantage of fetchmail over the older popclient is that the password does not appear in the process table but is only exchanged between the mail server and the POP3 client; the password itself is stored in a separate file.

Installation:

... of course there are many approaches, here just one example:

Let's say the mail server is mail.provider.com. There are two users, asterix and obelix, who are called eve and mary on the host. The passwords (on the mail server) are adam and joseph.

Multidrop Mode:

Some providers store the mail for various mail users in a single POP3 account. Using the above-mentioned solution, you are able to collect all mail, but the mail would be forwarded to one local user.

Find out whether the provider keeps the target address or rewrites it (usually to the mail account).

If the target address remains unchanged:

In this case, fetchmail can forward the mail directly to the MTA (sendmail, postfix). Make sure the MTA assumes responsibility for the incoming mail.
This is done by means of the options aka or localdomains. aka replaces the domain part with localhost. On the other hand, localdomains keeps the domain part, which means that the MTA must be configured accordingly. If this is not done, the mail is not distributed locally but is resent and comes back to the mailbox :-(. (mail loop!) .fetchmailrc may look somewhat like:
poll mail.provider.com protocol POP3 aka domain1 domain2  user asterix password adam is *
The mail delivery via MTA works us usual; aliases can be defined in /etc/aliases, and a virtusertable (sendmail) is set up (mainly necessary if several users in your system receive mail with the same mail user name, and only the domain part is diferent; in this case at least one of these addresses must be rewritten to another local user).

Example:
The following mail addresses arrive in your mailbox:
name1@prov1.com
name1@prov2.com
Normally, these messages would all be forwarded to the local mailbox name1 (or to a substitute mailbox stated in aliases)
Accordingly, one of the addresses must first be assigned to another user. For this purpose, use the following syntax in the file /etc/mail/virtusertable (sendmail):

name1@prov2.com           localusername
Then execute SuSEconfig.

Limitations:

If you receive mail that does not contain your mail address (e.g. from mailing lists or BCC headers), make sure these are not sent back with an error message ("user unknown"). You can prevent this from happening with the following setting (in .fetchmailrc):
set no bouncemail
However, mail of this kind can not be allocated to individual users, as fetchmail and sendmail can no longer determine to whom the message was originally sent. Therefore, this kind of mail goes to the postmaster.
If you are looking for a secure solution that provides something like a multidrop mailbox, ask your provider for a static IP address and ETRN or mail delivery by UUCP.

However, if you provider inserts an additional header containing the final recipient (e.g. Delivered-To in postfix or qmail, X-Originally-To etc.) you can configure fetchmail in such a way that the respective header is processed.
For this purpose you need the option envelope.
Accordingly, the respective entry in .fetchmailrc may look as follows:
poll mail.provider.com envelope Delivered-To: protocol POP3
   aka domain1 domain2  user asterix password adam is *
If you use qmail, make sure you start fetchmail with the command-line option --qvirtual qmailprefix-.

If the target address is rewritten:

In this case fetchmail has no possibility to identify the recipient. The only possibility is to examine the mail header.

To do this, we suggest that you set up a special user (e.g. mailer) that forwards mail by means of a ~/.procmailrc file.

Examples can be found under http://www.linuxdoc.org/HOWTO/mini/Offline-Mailing.html.


See also:
o fetchmail cannot fetch mails

Keywords: FETCHMAIL, POP3, SENDMAIL, MAIL, IMAP

Categories: Email

SDB-fetchmail, Copyright SuSE Linux AG, Nürnberg, Germany - Version: 02. Apr 1997
SuSE Linux AG - Last generated: 02. Aug 2002 by sdb (sdb_gen 1.40.0)