Implementing Mandrill with Exim on cPanel
- Written by Vanessa Vasile
- Published in Howto, Mail
- 14 Comments
- Permalink
Mandrill is a transactional email service run by MailChimp, comparable to SendGrid. It comes stock with a powerful API for fast implementation into applications for sending email reliably over SMTP, but it can also be used as a smart host for all of your server’s outgoing email.
The below instructions cover how to do this via command line. If you prefer WHM, simply go to WHM -> Exim Configuration Manager -> Advanced Editor and alter the sections indicated.
First, open up your /etc/exim.conf.local file in an editor and look for the @AUTH@ section. Modify it to look like this:
@AUTH@
auth_login:
driver = plaintext
public_name = LOGIN
hide client_send = : your@email : api_key
Note: If exim.conf.local doesn’t exist, create it. There’s a template here.
The value of api_key is not your Mandrill account password – it’s your API key. You can find it in your account settings under “SMTP & API Credentials”
Also, replace your@email with your Mandrill account email address. If you already have something in the AUTH section, simply add this block of text below it.
Now look for the @PREROUTERS@ section, and modify it to look like this:
@PREROUTERS@
smart_route:
driver = manualroute
domains = ! +local_domains
ignore_target_hosts = 127.0.0.0/8
transport = auth_relay
route_list = * smtp.mandrillapp.com
no_more
The last modification should be to the @TRANSPORTSTART@ section:
@TRANSPORTSTART@
auth_relay:
driver = smtp
port = 587
hosts_require_auth = $host_address
hosts_require_tls = $host_address
Save this file. Now open /etc/exim.conf.localopts and add this line (or modify it and append the hostname to the existing line)
smarthost_routelist=*: smtp.mandrillapp.com
If you’re using WHM, this is under Basic Editor -> Mail -> Smarthost support.
Save the file, and apply the changes:
/scripts/buildeximconf
service exim restart
To test whether things are working, send an email out from your server, and look for it in /var/log/exim_mainlog. You should see something like this in your log entry:
2014-03-11 21:59:50 1WNbGg-0006ud-2d => to@email R=smart_route T=auth_relay H=smtp.us-east-1.mandrillapp.com [x.x.x.x] X=UNKNOWN:ECDHE-RSA-AES256-GCM-SHA384:256 A=auth_login C="250 2.0.0 Ok: queued as 3529E193E178"
If you have SPF records, you’ll need to add the hostname of the SMTP server to the record itself to allow the third-party mail server to send email on behalf of your domain. Mandrill will provide the hostname you should use under Settings -> Sending Domains, when you do an SPF test.
14 Comments
Hi,
Is possible to use mandril or sendgrid, only for some domains?
Thanks,
Nice post, thank you so much!
VERY VERY VERY VERY VERY ATTENTION FOR PORT 2525!
I lost more of 2 weeks because nothing worked but I do not was tested port 2525.
Simple, add 2525 and not 587 in transport configuration! See…
@TRANSPORTSTART@
auth_relay:
driver = smtp
port = 2525
hosts_require_auth = $host_address
hosts_require_tls = $host_address
Various VPSs use this port and block all others!
If you use a custom SMTP port, sure. But this post doesn’t take into account every possible configuration you may have on your server. Please make sure you are aware of the changes you are making on a live server before you make them.
Great .. I have a question though, this will allow all accounts in whm to send mail through mandrill but that can also cause some complications where in my case a wordpress website was hacked and the hacker send about 16000 emails in a space f 2 hours .. The standard 200/hour email restriction does not seem to help when mandrill is active on whm ..
What might be the best way to tackle this ? Is they possible another account that can automatically suspend when something like this happens ?
The outgoing hourly limits should still be effective whether you are using Mandrill or not. Most likely, there were multiple recipients per email which is an easy way to bypass this restriction, which is why many hosts now limit the number of recipients allowed per email (ie, a single email with 100 recipients is still a single email, not 100 emails, though Mandrill counts it as 100 emails). You may also be able to set limits in your Mandrill account for things like this.
Is they a way of setting smarthosts for only one domain ? I use mandrill on my server and but all domains use mandrill, others just abuse the service so i only want Mandrill to send for only 1 or just a few domains now all of them , what is the best way to tackle this ?
Ok! Nice instructions.
And how to remove some domains from relay via mandrill?
When adding “senders = ! domain.com” in @PREROUTERS@, all email sent by this domain will trigger “R=fail_remote_domains: The mail server could not deliver mail to [email protected]. The account or domain may not exist, they may be blacklisted, or missing the proper dns entries.”
How to exclude some domains from mandrill?
How to exclude some domains from mandrill?
Pingback: Implementing Mandrill with Exim on cPanel – The cPanel Admin | ZeroLife
Hi,
Do you know of a fix in Cpanel for the Server Hostname Emails.
You cant Add SPF or DKim records, therefore you cant send or receive emails.
So root emails coming from the Server will just Bounce.
Thanks
Just add it manually to the DNS zone containing the hostname.
Vanessa,
Sorry for the Noobie questions.
Are you talking about adding a MX Record to “DNZ Zone???
server.example.com. MX Priority 0 server.example.com.
After setting up Mandrill via your guide, I keep getting Root Emails that are bouncing….
Change the existing MX record. However, for this change, there is no mention of needing MX records to route outbound mail.