Docs / Email Servers / Fetchmail for Remote Email Collection

Fetchmail for Remote Email Collection

By Admin · Mar 15, 2026 · Updated Apr 24, 2026 · 277 views · 3 min read

Fetchmail retrieves email from remote POP3 and IMAP servers and delivers it to your local mail system. It is useful for consolidating email from multiple accounts, migrating from external providers, or collecting email from ISP mailboxes for processing by your own mail server. This guide covers configuration, automation, and common use cases.

Installation

sudo apt install fetchmail    # Ubuntu/Debian
sudo dnf install fetchmail    # Rocky Linux

Basic Configuration

# ~/.fetchmailrc (per-user) or /etc/fetchmailrc (system-wide)
set daemon 300              # Poll every 5 minutes
set logfile /var/log/fetchmail.log
set no bouncemail
set postmaster root

# Fetch from a single POP3 account
poll pop.example.com
    protocol pop3
    username "user@example.com"
    password "Password123"
    ssl
    mda "/usr/bin/procmail -d %T"
    keep                    # Keep messages on server (remove to delete after fetch)

# Fetch from IMAP
poll imap.gmail.com
    protocol imap
    username "user@gmail.com"
    password "app-password"
    ssl
    folder INBOX
    fetchall               # Fetch all messages, not just new
    mda "/usr/sbin/sendmail -oi -f %F -- %T"
# Secure the config file
chmod 600 ~/.fetchmailrc

Multiple Accounts

# /etc/fetchmailrc
set daemon 300
set logfile /var/log/fetchmail.log

# Account 1: Corporate mail
poll mail.company.com
    protocol imap
    username "john@company.com"
    password "CompanyPass"
    ssl
    folder INBOX
    mda "/usr/sbin/sendmail -oi -f %F -- john@localdomain.com"

# Account 2: ISP mailbox
poll pop.isp.net
    protocol pop3
    username "john_doe"
    password "ISPPass"
    ssl
    mda "/usr/sbin/sendmail -oi -f %F -- john@localdomain.com"
    fetchlimit 50          # Fetch max 50 messages per poll

# Account 3: Gmail with multidrop
poll imap.gmail.com
    protocol imap
    username "team@gmail.com"
    password "app-password"
    ssl
    folder INBOX
    to team@localdomain.com
    mda "/usr/sbin/sendmail -oi -f %F -- %T"

Deliver to Postfix/Dovecot

# Using sendmail (Postfix) for local delivery
mda "/usr/sbin/sendmail -oi -f %F -- %T"

# Using Dovecot deliver
mda "/usr/lib/dovecot/deliver -d %T"

# Using procmail for filtering
mda "/usr/bin/procmail -d %T"

# Using LMTP
mda "/usr/bin/lmtp-client -a %T localhost:24"

Running as a Service

# /etc/systemd/system/fetchmail.service
[Unit]
Description=Fetchmail Email Retrieval
After=network-online.target

[Service]
Type=simple
User=fetchmail
ExecStart=/usr/bin/fetchmail -f /etc/fetchmailrc --daemon 300 --nodetach
Restart=on-failure
RestartSec=30

[Install]
WantedBy=multi-user.target
sudo systemctl enable --now fetchmail

Gmail-Specific Configuration

# Gmail requires:
# 1. Enable IMAP in Gmail settings
# 2. Create App Password (Settings → Security → App Passwords)
# 3. Use app-specific password, not your Google account password

poll imap.gmail.com
    protocol imap
    username "user@gmail.com"
    password "xxxx-xxxx-xxxx-xxxx"    # App password
    ssl
    sslcertck
    sslcertpath /etc/ssl/certs
    folder "[Gmail]/All Mail"         # Or INBOX for inbox only
    fetchall
    keep
    mda "/usr/sbin/sendmail -oi -f %F -- localuser@example.com"

Troubleshooting

# Test configuration (verbose mode)
fetchmail -v -f ~/.fetchmailrc --nodetach

# Check for connection issues
fetchmail -v --check

# Common errors:
# "Authorization failure" → wrong password or 2FA not configured
# "Connection timed out" → firewall blocking POP3/IMAP ports
# "SSL certificate problem" → add sslcertck and sslcertpath
# "Lock busy" → another fetchmail instance is running (kill it)

Best Practices

  • Always use SSL/TLS for POP3 (port 995) and IMAP (port 993) connections
  • Secure .fetchmailrc with chmod 600 — it contains passwords
  • Use keep during initial setup to avoid losing email; remove once everything works
  • Set fetchlimit to avoid overwhelming your local server during catch-up
  • Use IMAP over POP3 when possible — it supports folders and server-side state
  • For Gmail, always use App Passwords rather than your main Google password
  • Monitor the log file for delivery failures and connection errors

Was this article helpful?