Using Mandrill with sSMTP

MandrillMost of you might have heard of Mandrill, a service by MailChimp capable of sending e-mails trough a REST API. It also offers traditional SMTP functionality. But why would you use such a service instead of a locally installed MTA like exim4 or postfix? This post describes why I switched my load balanced web servers to use Mandrills SMTP feature (in only a few minutes), and how I use it with sSMTP, a lightweight mail relay program to send mails with PHP.

I’m running a few nginx powered web servers and until a few days ago I configured exim4 to send system mails and notifications generated by WordPress (well, PHP, that is). In the last few years I’ve had some problems with deliverability because my machines were not always configured quite good (bad). Of course the guys from MailChimp know better how to run real mail transfer services. The advantage of Mandrill is, that you can’t only use it trough an API but also use it as an external SMTP server while still having searchable logs and statistics of every mail. Don’t worry about IPs or misconfiguration anymore.

By using sSMTP to relay locally generated mail to Mandrill, the servers save a lot of resources. Mandrill ist free for the first 12’000 mails, after that, it’s 0.20$ per 1000 mails. In my opinion a good price given the fact that you get a lot of statistics, logs and tools to help improving deliverability for sending domains (e.g. validation- and test tools, tips for SPF records and DKIM settings). But that’s enough for now, I might do an in-depth review for Mandrill another time (and maybe in german).

Installation and configuration

First we need to install sSMTP which is developed by the debian community, hence it’s available (at least) on every debian based linux distribution. Most of those systems will work this way:

sudo apt-get install ssmtp

Next, we need to create an account with Mandrill. Just go to their website and create an account. After this you go to „SMTP & API Credentials“, where you will find your SMTP credentials. Create an API-Key that will serve as password. You can also set this key to only work from certain IPs.

Next, use a text editor to edit the file /etc/ssmtp/ssmtp.conf and add your credentials along with some options:

# ---- basic config
root=admin_email@example.com
AuthMethod=LOGIN
UseSTARTTLS=YES
hostname=fqdn_of_your_server.example.com
FromLineOverride=YES
# ---- mandrill config
AuthUser=your_mandrill_email@example.com
mailhub=smtp.mandrillapp.com:587
AuthPass=mandrill_api_key

After saving, sSMTP already works and replaces sendmail. Just to make sure it works with your PHP installation, you might want to change the following line in your php.ini:

sendmail_path = /usr/sbin/ssmtp -t

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert