<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://otremba.net/w/index.php?action=history&amp;feed=atom&amp;title=Fetchmail_%28Debian%29</id>
	<title>Fetchmail (Debian) - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://otremba.net/w/index.php?action=history&amp;feed=atom&amp;title=Fetchmail_%28Debian%29"/>
	<link rel="alternate" type="text/html" href="https://otremba.net/w/index.php?title=Fetchmail_(Debian)&amp;action=history"/>
	<updated>2026-04-19T08:42:00Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Matts Wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://otremba.net/w/index.php?title=Fetchmail_(Debian)&amp;diff=2459&amp;oldid=prev</id>
		<title>Matt am 23. September 2020 um 21:26 Uhr</title>
		<link rel="alternate" type="text/html" href="https://otremba.net/w/index.php?title=Fetchmail_(Debian)&amp;diff=2459&amp;oldid=prev"/>
		<updated>2020-09-23T21:26:52Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article describes different use cases for Fetchmail as well as how they can be implemented with Dovecot IMAP Server on Debian 10.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
There are four major use cases for downloading mails with Fetchmail:&lt;br /&gt;
&lt;br /&gt;
* Download manually via IMAP or POP protocol&lt;br /&gt;
* Download periodically via IMAP or POP protocol by daemon&lt;br /&gt;
* Download periodically via IMAP or POP protocol by cronjob&lt;br /&gt;
* Download instantly via IMAP IDLE connection&lt;br /&gt;
&lt;br /&gt;
IMAP IDLE can be used by default only for one account. There is a script on the internet which creates multiple instances which enables the administrator to create multiple IMAP IDLE connections each to a different account. It&amp;#039;s use and how to alter it to work on Debian is described below.&lt;br /&gt;
&lt;br /&gt;
== Install Fetchmail on Debian ==&lt;br /&gt;
&lt;br /&gt;
Install:&lt;br /&gt;
&lt;br /&gt;
 apt-get install fetchmail&lt;br /&gt;
&lt;br /&gt;
== Locations and Permissions of Configuration Files ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!File&lt;br /&gt;
!Content&lt;br /&gt;
!Owner&lt;br /&gt;
!Permissions&lt;br /&gt;
|-&lt;br /&gt;
|/etc/fetchmailrc &lt;br /&gt;
|System config&lt;br /&gt;
|fetchmail:root&lt;br /&gt;
|600&lt;br /&gt;
|-&lt;br /&gt;
|~/.fetchmailrc&lt;br /&gt;
|User config&lt;br /&gt;
|user:user&lt;br /&gt;
|600&lt;br /&gt;
|-&lt;br /&gt;
|~/.netrc&lt;br /&gt;
|Passwords for user config&lt;br /&gt;
|user:user&lt;br /&gt;
|600&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As configuration files contain user names and passwords their permissions should be set to 600.&lt;br /&gt;
&lt;br /&gt;
== Manual Download ==&lt;br /&gt;
&lt;br /&gt;
=== Download INBOX to Default Inbox ===&lt;br /&gt;
&lt;br /&gt;
Start Fetchmail in user context either using user config with:&lt;br /&gt;
&lt;br /&gt;
 fetchmail&lt;br /&gt;
&lt;br /&gt;
Or with a specific config:&lt;br /&gt;
&lt;br /&gt;
 fetchmail -f &amp;lt;/path/to/specific/fetchmailrc-config-file&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example for &amp;lt;code&amp;gt;~/.fetchmailrc&amp;lt;/code&amp;gt; which downloads all mails from INBOX folder at the specified host:&lt;br /&gt;
&lt;br /&gt;
 poll host.domain.tld protocol IMAP&lt;br /&gt;
      user &amp;quot;&amp;lt;username@host.domain.tld&amp;gt;&amp;quot; with pass &amp;quot;&amp;lt;password&amp;gt;&amp;quot; is &amp;quot;&amp;lt;username@localhost&amp;gt;&amp;quot; here&lt;br /&gt;
      ssl fetchall&lt;br /&gt;
&lt;br /&gt;
Remember to restrict permissions for that file in order to prevent other users to see your password.&lt;br /&gt;
&lt;br /&gt;
There is also another variant of storing passwords which is described in section [[#Passwords in Configuration Files|Passwords in Configuration Files]]&lt;br /&gt;
&lt;br /&gt;
=== Download Selected Remote Folder to Specific Local Folder ===&lt;br /&gt;
&lt;br /&gt;
An email fetched by fetchmail will be delivered to SMTP port 25 on the local machine by default. That prevents a specification to which local folder an email should be delivered to. In order do deliver emails from a selected remote folder to a specific local folder one has to use the MDA parameter.&lt;br /&gt;
&lt;br /&gt;
When using the MDA parameter the MTA for SMTP running at port 25 will be bypassed and the email will be directly handled by the specified MDA. &lt;br /&gt;
&lt;br /&gt;
Example for delivering emails from the remote folder called &amp;quot;Sent&amp;quot; to the local folder called &amp;quot;Sent&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 poll host.domain.tld protocol IMAP&lt;br /&gt;
      user &amp;quot;&amp;lt;username@host.domain.tld&amp;gt;&amp;quot; is &amp;quot;&amp;lt;username@localhost&amp;gt;&amp;quot; here&lt;br /&gt;
      folder Sent&lt;br /&gt;
      ssl fetchall&lt;br /&gt;
      mda &amp;quot;/usr/lib/dovecot/deliver -d &amp;lt;username@localhost&amp;gt; -m Sent&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Periodical Download ==&lt;br /&gt;
&lt;br /&gt;
=== Fetchmail Running as Daemon ===&lt;br /&gt;
&lt;br /&gt;
Enable Daemon in config file &amp;#039;&amp;#039;&amp;#039;/etc/default/fetchmail&amp;#039;&amp;#039;&amp;#039; by changing the following line to:&lt;br /&gt;
&lt;br /&gt;
 START_DAEMON=yes&lt;br /&gt;
&lt;br /&gt;
In the system specific config file &amp;#039;&amp;#039;&amp;#039;/etc/fetchmailrc&amp;#039;&amp;#039;&amp;#039; a polling interval in seconds will be set for the daemon with &amp;quot;set daemon&amp;quot;. Following that all mailboxes will be specified. It is possible to skip a interval for a mailbox by specifing the &amp;quot;interval&amp;quot; parameter followed by a number which says how many intervals should be skipped. Example:&lt;br /&gt;
&lt;br /&gt;
 set daemon 60&lt;br /&gt;
 &lt;br /&gt;
 poll host1.domain.tld protocol IMAP interval 3&lt;br /&gt;
      user &amp;quot;&amp;lt;username@host1.domain.tld&amp;gt;&amp;quot; with pass &amp;quot;&amp;lt;password&amp;gt;&amp;quot; is &amp;quot;&amp;lt;username@localhost&amp;gt;&amp;quot; here&lt;br /&gt;
      ssl fetchall&lt;br /&gt;
      smtp localhost&lt;br /&gt;
 &lt;br /&gt;
 poll host2.domain.tld protocol IMAP interval 10&lt;br /&gt;
      user &amp;quot;&amp;lt;username@host2.domain.tld&amp;gt;&amp;quot; with pass &amp;quot;&amp;lt;password&amp;gt;&amp;quot; is &amp;quot;&amp;lt;username@localhost&amp;gt;&amp;quot; here&lt;br /&gt;
      ssl fetchall&lt;br /&gt;
      smtp localhost&lt;br /&gt;
&lt;br /&gt;
=== Fetchmail Running as Cronjob ===&lt;br /&gt;
&lt;br /&gt;
Fetchmail can also be run in user context by specifing a user specific cronjob with &amp;lt;code&amp;gt;crontab -e&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Content can be somewhat like this for running the user specific config every day at 2:30 am:&lt;br /&gt;
&lt;br /&gt;
 30 2 * * * fetchmail&lt;br /&gt;
&lt;br /&gt;
or like this for running a specific config:&lt;br /&gt;
&lt;br /&gt;
 30 2 * * * fetchmail -f &amp;lt;/path/to/specific/fetchmailrc-config-file&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For details see section [[#Manual_Download|Manual Download]] as well as [[Cronjob (Debian)]]&lt;br /&gt;
&lt;br /&gt;
== Immediate Download via IMAP IDLE ==&lt;br /&gt;
&lt;br /&gt;
=== Single IMAP IDLE Instance for Single Account ===&lt;br /&gt;
&lt;br /&gt;
IMAP IDLE can be used in the system config &amp;#039;&amp;#039;&amp;#039;/etc/fetchmailrc&amp;#039;&amp;#039;&amp;#039; in order to have it active after a reboot. Example:&lt;br /&gt;
&lt;br /&gt;
 poll host.domain.tld protocol IMAP&lt;br /&gt;
      user &amp;quot;&amp;lt;username@host.domain.tld&amp;gt;&amp;quot; with pass &amp;quot;&amp;lt;password&amp;gt;&amp;quot; is &amp;quot;&amp;lt;username@localhost&amp;gt;&amp;quot; here&lt;br /&gt;
      idle&lt;br /&gt;
      ssl&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Hint:&amp;#039;&amp;#039;&amp;#039; This works only with one Fetchmail instance and therefore only one IMAP IDLE connection per server as the connection persists as soon as it was started.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Workaround:&amp;#039;&amp;#039;&amp;#039; In order to have multiple Fetchmail instances with multiple IMAP IDLE connections for different mailboxes each Fetchmail instance has to have it&amp;#039;s own process ID:&lt;br /&gt;
&lt;br /&gt;
=== Multiple IMAP IDLE Connections for Multiple Mailboxes ===&lt;br /&gt;
&lt;br /&gt;
Source: http://fnxweb.com/blog/2012/07/14/using-multiple-fetchmail-instances-for-instant-gratification/&lt;br /&gt;
&lt;br /&gt;
The description above is altered to match Debian folders and security.&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
http://www.fnxweb.com/data/fetchmail-service --&amp;gt; Save as fetchmail-imap-idle at &amp;#039;&amp;#039;&amp;#039;/usr/local/bin&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
http://www.fnxweb.com/data/fetchmail.service --&amp;gt; Save as fetchmail-imap-idle.service at &amp;#039;&amp;#039;&amp;#039;/usr/local/bin&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Add execute permissions:&lt;br /&gt;
&lt;br /&gt;
 chmod +x /usr/local/bin/fetchmail-imap-idle&lt;br /&gt;
&lt;br /&gt;
Create symbolic link to fetchmail-imap-idle.service in &amp;#039;&amp;#039;&amp;#039;/etc/systemd/system&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
 ln -s /usr/local/bin/fetchmail-imap-idle.service /etc/systemd/system/fetchmail-imap-idle.service&lt;br /&gt;
 &lt;br /&gt;
Place config files at: &amp;#039;&amp;#039;&amp;#039;/etc/fetchmail.conf.d/*.conf&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Each config file should contain only one IMAP connection.&lt;br /&gt;
&lt;br /&gt;
Example &amp;#039;&amp;#039;/etc/fetchmail.conf.d/my-imap-account1-inbox.conf&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 poll host.domain.tld protocol IMAP&lt;br /&gt;
      user &amp;quot;&amp;lt;username@host.domain.tld&amp;gt;&amp;quot; with pass &amp;quot;&amp;lt;password&amp;gt;&amp;quot; is &amp;quot;&amp;lt;username@localhost&amp;gt;&amp;quot; here&lt;br /&gt;
      idle&lt;br /&gt;
      ssl&lt;br /&gt;
&lt;br /&gt;
Avoid parameter &amp;#039;&amp;#039;&amp;#039;fetchall&amp;#039;&amp;#039;&amp;#039; in IMAP IDLE config files as this leads to somewhat intransparent behavior of the local dovecot LDA and emails don&amp;#039;t appear at once rather than somewhat delayed. &lt;br /&gt;
&lt;br /&gt;
Fix: Try to send another mail to remote mailbox. After that it seems that all missing mails appear magically in Dovecot mailbox.&lt;br /&gt;
&lt;br /&gt;
Alter &amp;#039;&amp;#039;&amp;#039;/usr/local/bin/fetchmail-imap-idle&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
Change lines 10 and 11 as follows:&lt;br /&gt;
&lt;br /&gt;
 fetchmailuser=fetchmail&lt;br /&gt;
 fetchmailgroup=nogroup&lt;br /&gt;
&lt;br /&gt;
Alter paths and executable names in &amp;#039;&amp;#039;/etc/systemd/system/fetchmail.service&amp;#039;&amp;#039; as follows:&lt;br /&gt;
&lt;br /&gt;
 [Unit]&lt;br /&gt;
 Description=A remote mail retrieval and forwarding utility&lt;br /&gt;
 After=network-online.target sendmail.service &lt;br /&gt;
 &lt;br /&gt;
 [Service]&lt;br /&gt;
 ExecStart=/usr/local/bin/fetchmail-imap-idle start&lt;br /&gt;
 ExecReload=/usr/local/bin/fetchmail-imap-idle restart&lt;br /&gt;
 ExecStop=/usr/local/bin/fetchmail-imap-idle stop&lt;br /&gt;
 Type=forking&lt;br /&gt;
 GuessMainPID=no&lt;br /&gt;
 &lt;br /&gt;
 [Install]&lt;br /&gt;
 WantedBy=multi-user.target&lt;br /&gt;
&lt;br /&gt;
Activate service as follows:&lt;br /&gt;
&lt;br /&gt;
 systemctl enable fetchmail-imap-idle&lt;br /&gt;
 systemctl start fetchmail-imap-idle&lt;br /&gt;
&lt;br /&gt;
Service can be removed if necessary with:&lt;br /&gt;
&lt;br /&gt;
 systemctl stop fetchmail-imap-idle&lt;br /&gt;
 systemctl disable fetchmail-imap-idle&lt;br /&gt;
&lt;br /&gt;
=== Initial Download of Entire Mailbox ===&lt;br /&gt;
&lt;br /&gt;
First download of an entire mailbox should be done via manual downlod rather than via IMAP IDLE with &amp;#039;&amp;#039;&amp;#039;fetchall&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
For further information see [[#Manual Download|Manual Download]]&lt;br /&gt;
&lt;br /&gt;
== Further Information ==&lt;br /&gt;
&lt;br /&gt;
=== Passwords in Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;with pass &amp;lt;password&amp;gt;&amp;lt;/code&amp;gt; can be removed from file &amp;lt;code&amp;gt;~/.fetchmailrc&amp;lt;/code&amp;gt; for security reasons if the file &amp;lt;code&amp;gt;~/.netrc&amp;lt;/code&amp;gt; exists in the user profile. It contains passwords and will be read by fetchmail at runtime. Permissions for this file see section [[#Locations_and_Permissions_of_Configuration_Files|Locations and Permissions of Configuration Files]]&lt;br /&gt;
&lt;br /&gt;
This does not work with system config file &amp;lt;code&amp;gt;/etc/fetchmailrc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example for &amp;lt;code&amp;gt;~/.netrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 machine &amp;lt;host1.domain.tld&amp;gt;&lt;br /&gt;
 login &amp;lt;username@host1.domain.tld&amp;gt;&lt;br /&gt;
 password &amp;lt;pass&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 machine &amp;lt;host2.domain.tld&amp;gt;&lt;br /&gt;
 login &amp;lt;username@host2.domain.tld&amp;gt;&lt;br /&gt;
 password &amp;lt;pass&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Keep Emails on Source Server  ===&lt;br /&gt;
&lt;br /&gt;
Edit config file and replace parameter &amp;lt;code&amp;gt;fetchall&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;keep&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Use of Additional Files ===&lt;br /&gt;
&lt;br /&gt;
 fetchmail -f &amp;lt;config-filename&amp;gt;        # Specify config file&lt;br /&gt;
 fetchmail --pidfile &amp;lt;pidfile&amp;gt;         # Specify process ID file&lt;br /&gt;
&lt;br /&gt;
=== Remove Unseen Flag in Sent Folder ===&lt;br /&gt;
&lt;br /&gt;
When using Fetchmail to download Sent folder every downloaded mail will be flagged as unseen.&lt;br /&gt;
&lt;br /&gt;
In order to mark them seen create following cronjob with &amp;lt;code&amp;gt;crontab -e&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 */3 * * * * doveadm flags add -u &amp;lt;username@localhost&amp;gt; &amp;#039;\Seen&amp;#039; mailbox Sent unseen &lt;br /&gt;
&lt;br /&gt;
== Sources ==&lt;br /&gt;
&lt;br /&gt;
IMAP IDLE: http://fnxweb.com/blog/2012/07/14/using-multiple-fetchmail-instances-for-instant-gratification/&lt;br /&gt;
&lt;br /&gt;
Manpage: http://www.fetchmail.info/fetchmail-man.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux]]&lt;br /&gt;
[[Category:E-Mail]]&lt;/div&gt;</summary>
		<author><name>Matt</name></author>
	</entry>
</feed>