Fetchmail-Draft
Fetchmail is a mail client designed to retrieve mail (via imap or pop) from another server and deliver it via smtp to the local mail server. There are many reasons you may want to use fetch mail; this document describes using it to create a local cache of mail from a cloud mail provider. It uses the system wide configuration option via the /etc/fetchmailrc config file.
Install Fetchmail
pkg_add fetchmail
Edit /etc/fetchmailrc to look like this:
# /etc/fetchmailrc for system-wide daemon mode # This file must be chmod 0600, owner fetchmail set daemon 150 # Pool every 2.5 minutes set syslog # log through syslog facility set postmaster root set no bouncemail # avoid loss on 4xx errors # on the other hand, 5xx errors get # more dangerous... ########################################################################## # Hosts to pool ########################################################################## # Defaults =============================================================== # Set antispam to -1, since it is far safer to use that together with # no bouncemail defaults: timeout 300 antispam -1 batchlimit 100 set logfile /var/log/fetchmail.log
Now, you need to add pull commands for each of the mail accounts you want to retrieve mail from. Lets assume you have 3 mail accounts on a remote server of example.com; user1, user2, and user3. All 3 use imap and the password "top!secret". We want to get all the mail over a secure ssl connection, for each user and deliver to the local users here.
Add this to the bottom if the file above given this example. You're exact config will very as needed.
poll mail.example.com protocol imap user "user1@example.com" there with password "top!secret" is "user1" here fetchall ssl poll mail.example.com protocol imap user "user2@example.com" there with password "top!secret" is "user2" here fetchall ssl poll mail.example.com protocol imap user "user3@example.com" there with password "top!secret" is "user3" here fetchall ssl
Special Notes
1. Bounced messages about a mail loop in Postfix
This May be similar in other mail servers also. Had an issue with postfix detecting mail with a Delievered-To: header as indicating a mail loop. To resolve you have to add a filter like this:
#Taken from: https://unix.stackexchange.com/questions/642677/postfix-delivery-problem-status-bounced-mail-forwarding-loop-for-jeffexample # vim /etc/postfix/main.cf > header_checks = regexp:/etc/postfix/header_checks # vim /etc/postfix/header_checks > /^Delivered-To:.*/ IGNORE # postmap /etc/postfix/header_checks # service postfix restart # service postfix status