How to Set up fetchmail


How to pick up emails and forward with fetchmail

fetchmail is a utility for retrieving and forwarding e-mail; the Unix pioneer retrieves e-mail from remote mail servers and forwards them to the delivery system. The mail can then be retrieved using normal e-mail user agents such as mutt, elm, or mail.

What is fetchmail ?

The fetchmail utility can run in daemon mode to repeatedly queries one or more systems at a given interval, it collects emails from servers that support all common email retrieval services, such as POP3 and IMAP, also support the ESMTP-ETRN extension and the ODMR protocols.

This article describes how to use fetchmail on a CentOS smart host with Postfix. The e-mail from external mail service providers is retrieved and the recipient is redirected to the mailbox server that receives e-mail from the smart host. Mail accounts do not require forwarding, and the smart host also scans the e-mail for viruses and SPAM before they are delivered to the user’s mailbox.

fetchmail installation

For installation on CentOS 7, the extras repository is required, if not already available.

The fetchmail utility can be installed from the CentOS Extras repository.

We create the fetchmail configuration file for the daemon under /etc/sysconfig.

Copy Paste /etc/sysconfig/fetchmail

The Daemon Init script is created, here for a CentOS host on this the Postfix MTA is already running. As root with vi /etc/rc.d/init.d/fetchmaild

Copy Paste /etc/rc.d/init.d/fetchmail
dMake the init script executable.

Create the global fetchmailrc Recource configuration for operation as a daemon.

Copy Paste /etc/fetchmailrc

For each mail server retrieved from this email, a poll line is created. The aim is to retrieve the external mailbox from to the POP3 Server and to be delivered to the user via the localhost via Postfix to the Mailbox Server. To prevent logging in maillog, log is made in fetchmail instead of it.

Possibilities with fetchmail

fetchmail offers a number of syntactic subtleties to make it easier for fetchmailrc to read files. For example, the words and, with, has, wants, and options are ignored by fetchmail, as well as punctuation marks. While it is possible to provide credentials for a server on a row, common configurations are specified over a number of different lines. fetchmail is insensitive to whitespace unless the argument is in quotation marks and closing characters.

There are several options for the Poll statement (e.B. nofetchall (default), fetchall, keep, nokeep ).The meanings are as follows:

nofetchall: retrieve only new messages (default). Unless otherwise specified (i.e. fetchall, keep ), this means nofetchall.
fetchall: get all messages, seen or not.keep.
keep: do not delete any message on server.
nokeep: delete the read messages on server.

Create the fetchmail user and group and set the rights.

The fetchmail daemon starts.

After changing the fetchmailrc configuration, the systemd daemon have to restart.

You can check the fetchmail conversation to server with run the following command:

Test the fetchmailrc configuration file.

Check the fetchmail process.

The output may look something like this:

fetchmail logging now takes place in the fetchmail file.

The fetchmail man page outputs a lot of information.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *