[LinuxAdmin] E-mail with Push notifications with fetchmail

I have several e-mail accounts that are managed from a single server. The way they are managed consists in having fetchmail retrieving (fetching, indeed) every configured amount of seconds. Of course this is not ideal especially when you expect to receive something really important. Luckily there is a way to configure a “push-like” notification! I am going to quickly explain how to achieve this in few steps. I am not going to give you the background of reasons why we configure fetchmail in this specific way, we will go straight to the point.


  • We are going to arrange this configuration on a Debian GNU/Linux server (stable version).
  • It is possible to achieve the real time notifications only if your e-mail account supports IMAP protocol to retrieve data.
  • We will need to have multiple fetchmail instances running (no worries, everything will be essentially automated).
  • We need to make sure that in the new configurations of fetchmail we have the “idle” option.
  • I assume that you already have fetchmail installed and/or are familiar with it and its configuration files.

Step 1 – Install fetchmail-conf-d

To make it short and simple, we will need to have fetchmail daemon working in a different way than the standard one in Debian. If you want to have the background of why I strongly recommend you to start reading here and here.
In the last link you will also find the info about the package we are going to install as the person writing the blog is also the author of fetchmail-conf-d modified version we are going to install. So let’s clone the following repository that is a fork of the one of Marek Dopiera and that contains as a only different that the Fetchmail daemon will not run as root:

git clone https://github.com/Unclezz/fetchmail-conf-d.git

After we have cloned the repo we can proceed with building the package while we make sure we have packages to do so:

# apt install devscripts
# apt install dh-systemd
# cd fetchmail-conf-d/
# debuild -us -uc -F

Package should now be ready, let’s install it:

# cd ..
# dpkg -i fetchmail-conf-d_0.1_all.deb

All should be now ready to start configuring the “new” fetchmail.

Step 2 – Stop the previously running daemon (if any) and create the new configuration files

If you are currently running a fetchmail daemon with the classical fetchmailrc configuration, it’s time to stop it:

# systemctl stop fetchmail

Now, make sure you remove the fetchmailrc configuration files creating a backup of them. I leave to you how you want to do that.

It is time to create the new configuration files. The package we have just installed in the previous step expects to have a single file for each e-mail account you want to retrieve in the directory /etc/fetchmailrc.d. Moreover it expects to have the file named as <your_account>.config. As example I give you a fake file creation step:

# cd /etc/fetchmailrc.d
# vim my_imap_account.config

And now sample content of file:

poll your_provider_imap proto imap
       user ‘your_user’ there with password ‘your_password’ is <yourself> here options ssl idle

Let me highlight once again that you want to have IMAP as protocol and the idle option (this is actually the option that makes the “push-like” behavior).

Step 3 – Start, Stop, Status of fetchmail

You are now ready to start getting real time emails for the account above. You should add as many configuration files as accounts you want to get email from. Once done you can start the fetchmail daemon inthis way:

# systemctl start fetchmail@<your_account>

You can then monitor the status of the daemon this way:

# systemctl status fetchmail@<your_account>


# systemctl status fetchmail@* (to show status of all configured accounts)

Obviously you can also stop each single instance with command:

# systemctl stop fetchmail@<your_account>

Conclusion and and hints

The version of the fetchmail-conf-d I suggested you to install will run fetchmail as user “fetchmail”. If you created the new configuration files as root, considering you were working in the /etc directory, you want to make sure that you give proper permission to files and directories, otherwise fetchmail will miserably fail (to t-shoot you can have a look at output of /var/log/syslog). My recommendation is to make as owner of the .config files the fetchmail user and then give 600 permission to them. Moreover, make sure that the also the /etc/fetchmailrc.d directory belongs to fetchmail and has -rx permission for it!


Related Post

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.