Use Linux as mail proxy

Q I want to download my emails from my ISP account automatically and use my Windows laptop to retrieve them from the Linux box, thus not having to download them on one machine and then also the next and also leave them on my host's server. I would just alter the MX records to point to my own box, but my IPS doesn't offer a static IP service (ruling out dyndns).

A Running a local MTA (Mail Transport Agent) without a static IP address is risky: changes in dynamic addressing could cause your mail to be delivered elsewhere. Some ISPs block port 25: it's a potential point of entry for would-be attackers. But, you don't need to run your own MTA to achieve what you want. You can use fetchmail to pull mail from your ISP's mail server, store it locally, then run a POP3 or IMAP server to serve that mail to your local PCs. With a text editor, create .fetchmailrc in your home directory with these contents

set daemon 300
poll with proto POP3
user 'myispuser' there with password
'mypass' is 'myuser' here options keep
mda '/usr/bin/procmail -d %T'

and set it to be readable by only your user with

chmod 600 ~/.fetchmailrc

The first part tells fetchmail to run in daemon mode and poll your ISP's mailserver every 300 seconds, the second gets the mailserver to contact and username and password to use, and the local username to save the mail for. The keep option leaves mail on the server (remove once you're sure everything works). The last line tells fetchmail to use procmail to deliver mail instead of running it through sendmail. Tell procmail to deliver the mail by putting this in ~/.procmailrc


The trailing / is important, it tells procmail to use maildir storage, which is needed by the IMAP server later. Create the mail directory with

mkdir -p /var/spool/mail/myuser
chown myuser:mail /var/spool/mail/myuser
chmod 770 /var/spool/mail/myuser

Test it with fetchmail --daemon 0 -v. This turns off the background mode and shows all that is happening. If it works, set fetchmail to auto-run by selecting System > Preferences > Personal > Session, pressing New in the Startup Programs tab and typing fetchmail in both boxes. Fetchmail will now run each time Gnome starts. Now the mail is on your system, you need an IMAP server to be able to access it from your LAN. Once Dovecot is installed from the Fedora repositories, make changes to /etc/dovecot.conf. Find lines

#listen= [::]
#mail_location =

and change them to

listen = *
mail_location = /var/spool/mail/%u

You also need to allow ports 110 (POP3) and 143 (IMAP) through your firewall. For outgoing email, each computer can be left set to communicate directly with your ISP's SMTP server.

Follow us on or Twitter

Username:   Password: