Integrating Mandrill and Postfix

Can Burak Çilingir
2 min readJun 29, 2013

--

This is an old post migrated from my blog, around May 2012. Please leave a note if it is still usable or broken.

I was looking around for transactional email solutions and decided to test Mandrill. The easiest test case for me was to setup my laptop to relay over it. I am using Ubuntu 12.04. You can find your credentials in the settings page.

An easier method would be using swaks:

swaks —to YOUR_EMAIL \
—server smtp.mandrillapp.com \
—auth-user YOUR_USERNAME \
—auth-password YOUR_API_KEY

First step is to set a fully qualified domain as your hostname. Check if hostname -f outputs an fqdn. On my laptop it nicely displayed gem.canb.net, so I was good to go. Please configure your hostname if it is not an FQDN. You can do it with the command hostname YOUR_FQDN. If you want this to survive a reboot, you are on your own.

Add this domain to your Mandrill account as outbound and set-up the DNS records as instructed by the DNS Settings button.

From now on, I’ll be closely following Postfix SASL documentation. Put the following into /etc/postfix/sasl_passwd:

[smtp.mandrillapp.com]:587 YOUR_USERNAME:YOUR_API_KEY

Secure the file with chown root:root and chmod go-rwx and run postmap /etc/postfix/sasl_passwd. You’ll need postmap anytime you change your credentials.

Modify /etc/postfix/main.cf:

myhostname = gem.canb.net
mydestination = gem.canb.net, gem, localhost.localdomain, localhost
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
relayhost = [smtp.mandrillapp.com]:587

If you are going to use this setup for a longer time period, you have to setup TLS as we are sending everything in plaintext, thanks to smtp_sasl_security_options = noanonymous.

Restart Postfix and you can ps aux | mail -s test YOUR_EMAIL. You can tail -f /var/log/syslog to see what’s happening.

--

--