Fetchmail

From DreamHost
Jump to: navigation, search

Fetchmail is an open source mail fetcher. It allows you to fetch messages from a POP or IMAP account and deliver it locally or via SMTP.


This article or section may require a cleanup.
We are hoping to create articles that meet certain standards. Please discuss this issue on the talk page. Editing help is available.
The instructions provided in this article or section require shell access unless otherwise stated.

You can use the PuTTY client on Windows, or SSH on UNIX and UNIX-like systems such as Linux or Mac OS X.
Your account must be configured for shell access in the Control Panel.
More information may be available on the article's talk page.

The instructions provided in this article or section are considered advanced.

You are expected to be knowledgeable in the UNIX shell.
Support for these instructions is not available from DreamHost tech support.
Server changes may cause this to break. Be prepared to troubleshoot this yourself if this happens.
We seriously aren't kidding about this.

Downloading and installing Fetchmail

You have to prepare your shell account as shown in unix account setup.

  • Download and open the latest version of Fetchmail (the example will use version 6.3.17, current as of Jun 2010) from [1].
cd ${HOME}/soft
FMVERSION=6.3.17
wget http://download.berlios.de/fetchmail/fetchmail-${FMVERSION}.tar.bz2
tar xvjf fetchmail-${FMVERSION}.tar.bz2
cd fetchmail-${FMVERSION}
  • Configure, compile and install.
./configure --prefix ${RUN}
make
make install

Setting Up Fetchmail

NOTE: In all steps below, replace example.net with your domain name, remoteuser/remotepassword with user name and password at Dreamhost, and localuser and localhost with the local user name and local host name. Local host name can be 'localhost'.

  • Edit $HOME/.fetchmailrc
  • Add the following lines:
# Configuration created Sun Apr 14 09:44:05 2002 by fetchmailconf
set postmaster "localuser"
#set bouncemail
set no spambounce
set properties ""

poll mail.example.net with proto POP3
       user 'remoteuser' there with password 'remotepassword' is 'localuser' here smtpname <you@yourdomainname.com> 

UPDATE: Sometime in April 2012, Dreamhost's security policy seems to have changed. In order to prevent spam, senders of mail via SMTP must be identified. This doesn't affect VPS-owners, who can be identified by their VPS. However, users sending e-mails from shared-hosting shell accounts have to use ESMTP to identify themselves.

Here's an updated $HOME/.fetchmailrc file.

set postmaster "localuser"
#set bouncemail
set no spambounce
set properties ""

poll mail.example.net with proto POP3
       esmtpname 'localuser' esmtppassword 'localuserpassword'
       user 'remoteuser' there with password 'remotepassword' is 'localuser' here smtpname <you@yourdomainname.com> 
  • Try the setup running:
 fetchmail -b 1 -B 1 -c -v
  • The specified flags are:
-b 1 Limit to one e-mail to be sent to SMTP
-B 1 Limit to one e-mail being fetched from POP3
-c Check only without removing any e-mail from the server
-v Be more verbose
  • Once fetchmail retrieves e-mails correctly, add it to crontab with something like:
#m   h   d   m   w
*/15   *   *   *   * $HOME/run/bin/fetchmail >> /dev/null 2>&1

running with ssl

This prevents man-in-the-middle attacks. Note this doesn't encrypt your communication with the mailserver....

First get the certificate Dreamhost uses (this may change once in a while)

openssl s_client -connect homie.mail.dreamhost.com:995 -showcerts | tee -a /tmp/dreamhost_openssl.txt

Then create a fingerprint out of this certificate

openssl x509 -fingerprint -md5 -noout -in /tmp/dreamhost_openssl.txt

Lastly, add the fingerprint to fetchmailrc like this:

set postmaster "localuser"
#set bouncemail
set no spambounce
set properties ""

poll mail.example.net with proto POP3
       esmtpname 'localuser' esmtppassword 'localuserpassword'
       user 'remoteuser' there with password 'remotepassword' is 'localuser' here smtpname <you@yourdomainname.com> sslfingerprint 'xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx'

Troubleshooting

  • Keep in mind any mail received through Fetchmail counts towards Dreamhost's SMTP quota. If you receive a lot of mail (or just a few of those chain letters my wife receives), you will lose mail! 100 recipients an hour is easy to hit in this scenario. It's also quite confusing for whoever is sending you the mail. They will receive a SENDER_QUOTA_REJECTION from your dreamhost domain rather than your ISP's domain, and this will get really confusing ("I thought I sent it to bob@earthlink.net, why is it saying it tried to send it to bobearthlinkpop@mydomain.com?")


External Links