Install and get e-mail with fetchmail daemon (2024)

()

fetchmail daemon pick up e-mails and forward to local mailbox

fetchmail is a daemon 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 e-mail program can run in daemon mode to repeatedly queries one or more systems at a given interval, it collects e-mails from servers that support all common e-mail 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.

Install fetchmail e-mail daemon

To install fetchmail e-mail daemon on CentOS 7, the extras repository is required, if not already available.

$ wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm$ sudo rpm -Uvh epel-release-latest-7*.rpm

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

$ yum -y install fetchmail

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

# This file will be used to declare some vars for fetchmail## Uncomment the following if you dont want localized log messages# export LC_ALL=C# Declare here if we want to start fetchmail. 'yes' or 'no'START_DAEMON=yes

Copy Paste /etc/sysconfig/fetchmail

The fetchmail e-mail 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

#!/bin/sh# chkconfig: 35 99 00# description: Start and stop fetchmail. /etc/init.d/functionsstart() { echo "Starting fetchmaild..." su fetchmail -s /bin/sh -c "fetchmail -vv -d 900 -a -f /etc/fetchmailrc -L /var/log/fetchmail" }stop() { echo "Shutting down fetchmaild..." su fetchmail -s /bin/sh -c "fetchmail --quit" }case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo "Usage: $0 {start|stop|restart}" ;;esacexit 0

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

$ chmod 0755 /etc/rc.d/init.d/fetchmaild

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

set daemon 900set no syslogset logfile /var/log/fetchmailset postmaster "postmaster"set no bouncemailset no spambounceset properties ""poll mail.foo.org with proto POP3user 'joe@foo.org' there with password 'secret' is joe.office@foo.com here options fetchall nokeep ssl smtphost localhost

Copy Paste /etc/fetchmailrc

For each mail server fetchmail retrieved from this e-mail, a poll line is created. The aim is to retrieve the external mailbox from joe@foo.org to the POP3 Server mail.foo.org and to be delivered to the user joe.office@foo.com 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.

fetchmail options

There are fetchmail provide 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.

$ groupadd -r fetchmail$ useradd -r -m -g fetchmail -s /sbin/nologin fetchmail$ chown fetchmail /etc/fetchmailrc$ chmod 0600 /etc/fetchmailrc$ touch /var/log/fetchmail$ chown fetchmail:fetchmail /var/log/fetchmail$ chmod 0600 /var/log/fetchmail

The fetchmail e-mail daemon starts.

$ /etc/rc.d/init.d/fetchmaild start

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

$ systemctl daemon-reload

fetchmail check

You can check the fetchmail e-mail daemon conversation to server with run the following command:

$ fetchmail -vv -N --ssl -p pop3 -P 995 -ujoe@foo.org mail.foo.org

Test the fetchmailrc configuration file.

$ fetchmail -v -a -k -f /etc/fetchmailrc

Check the fetchmail e-mail daemon process.

$ ps -ef | grep -v grep | grep fetchmail

The output may look something like this:

fetchma+ 4126 1 0 19:19 ? 00:00:00 fetchmail -vv -d 900 -a -f /etc/fetchmailrc -L /var/log/fetchmailroot 6488 3985 0 16:25 pts/0 00:00:00 su fetchmail

fetchmail daemon logging

fetchmail e-mail daemon logging now takes place in the fetchmail file.

$ tail -f /var/log/fetchmail

The fetchmail e-mail daemon man page outputs a lot of information.

$ man fetchmail

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

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?

Related posts:

  • How to fetchmail on Debian 11
  • Mail Server FQDN 450 Helo command rejected: Host not found
  • send mail mailx command
Install and get e-mail with fetchmail daemon (2024)

FAQs

How to install fetchmail? ›

Configuration
  1. Step 1: create user. Fetchmail does not need root or normal user privileges to run so it is suggested to create an unprivileged user and group for daemon based fetchmail configurations. ...
  2. Step 2: create directories. ...
  3. Step 3: set-up configuration. ...
  4. Step 4: starting the daemon. ...
  5. Step 5: testing the deamon.

Where does fetchmail store emails? ›

On the client side fetchmail probably stores mails in /var/spool/mail , unless you have set up your MTA. to deliver e.g. via procmail , in the later case your recipients ~/. procmailrc determines where things go. If you cannot seem to trace where things are going. Check your mail log (in fetched emails get bounced).

How does fetchmail work? ›

Fetchmail is a relatively simple program that downloads email from another server using the POP3 or IMAP protocol and delivers it to a mailbox on your system. It is most useful if you want to run your own mail server, but for some reason cannot have mail delivered directly.

What port does fetchmail use for IMAP? ›

This is generally a different port than the port used by the base protocol. For IMAP, this is port 143 for the clear protocol and port 993 for the SSL secured protocol; for POP3, it is port 110 for the clear text and port 995 for the encrypted variant.

How to check fetchmail version? ›

-V | --version

Displays the version information for your copy of fetchmail.

What is the keep option in fetchmail? ›

(Keyword: keep) Keep retrieved messages on the remote mailserver. Normally, messages are deleted from the folder on the mailserver after they have been retrieved. Specifying the keep option causes retrieved messages to remain in your folder on the mailserver. This option does not work with ETRN or ODMR.

What is the size limit for fetchmail? ›

fetchmail? default message size limit is 5MB (way too small by today's standards.)

What is the best port for IMAP? ›

Secure IMAP incoming and outgoing configuration

This is secure because the ports of 993 (incoming) and 465 (outgoing) are secure port numbers. SSL is also enabled which forces you to use these secure ports.

How do I find my IMAP server and port? ›

Select your email address, and under Advanced Settings, click Server Settings. You'll then be brought to your Android's Server Settings screen, where you can access your server information.

What is the default port number for IMAP? ›

If you enable the IMAP service, you can specify the port number that the server is to use for IMAP connections. The default is 143.

What port does IMAP STARTTLS use? ›

IMAP and POP (mainly POP3) also use different ports for Implicit and Explicit SSL/TLS. IMAP retrieves emails via port 143 when STARTTLS is in place and via port 993 when using Implicit SSL/TLS. POP uses ports 110 and 995, respectively.

Which ports are used by the IMAP protocol? ›

An IMAP server typically listens on well-known port 143, while IMAP over SSL/TLS (IMAPS) uses 993.

What is IMAP port 587? ›

Here's a quick overview: Port 587: This port is typically used for email submission by mail clients (e.g., Outlook, Thunderbird) to a mail server. It is part of the standards defined in the Simple Mail Transfer Protocol (SMTP) for email transmission.

What is the secure transport port for IMAP? ›

Unencrypted IMAP uses port 143, while encrypted IMAP uses port 993.

References

Top Articles
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 6140

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.