SMTP Relay via Mandrill Service

2014-01-10

Jitesh Doshi

SMTP Relay via Mandrill Service

How to configure Exim4 on Debian Linux to relay emails through Mandrill transactional email service.

If you have ever tried to send emails from your dedicated server in the cloud to either a mailing list or to individual users of your site, you would know that it is not as simple as it sounds. Depending upon the reputation of the IP address asigned to your server, many large email providers might block your emails - even though you have a perfectly legitimate reason to send this email, and your company has never spammed anyone. The solution we implemented was subscribing to the excellent Mandrill transactional email server from https://mandrillapp.com/ and sending all our emails via them. The problem then is how to makes sure all your emails as routed (relayed) through them? For your Drupal emails, you can use theMandrill module, but that covers only Drupal (and has other issues). So what we really did was route emails to Mandrill at SMTP MTA (Mail Transport Agent) configuration level itself. The rest of the article describes how.We use Debian Linux, which usesexim4as the default MTA. To reconfigure it, just runsudo dpkg-reconfigure exim4-config, and follow the screens. You can take the defaults, except in the following three cases:

  • Type of mail configuration - mail sent by smarthost; no local mail
  • System mail name - yourdomain.com (or whatever your primary domain name is)
  • IP address or host name of the outgoing smarthost - smtp.mandrillapp.com::587 (this is most important)

Exim4 - Type of mail configuration

Exim4 - System mail name

Exim4 - Outgoing smarthost

Exit the configuration program andthen there is one more VERY IMPORTANT thing. You must edit*/etc/exim4/passwd.clientfile (asrootor usingsudo*) and add the following line to it:

*.mandrillapp.com:[email protected]:your-mandrill-api-key

You can find your Mandrill API fromhttps://mandrillapp.com/settings/indexafter logging in.

That’s it. Now all emails going out of your server will be relayed through Mandrill, and thus (hopefully) not rejected by your recepient’s email providers. Happy emailing!