How to send and receive emails with Mandrill

https://mandrill.com/ is an email delivery system which is ideal for use in web applications to send and receive emails. Mandrill is developed by Mailchimp, the company behind the very successful email marketing software at http://mailchimp.com/

In the past, I wrote a quick guide, with code samples on how to use Mandrill to send email templates designed in Mailchimp

Sending emails with Mandrill

Once you log in to your Mandrill account, click on ‘Settings’. This page shows you the SMTP credentials you will need to begin sending emails from your web application.

If you don’t see an SMTP password, you’ll need to generate an API key using the button below the existing SMTP. This becomes your SMTP password.

Take a note of the HOST, Port, SMTP Username and SMTP Password to use in your web application.

In your web application, update your SMTP details with the details from above and you’re ready to send.

Mandrill automatically adds any domain you use for sending through Mandrill to its control panel. Mandrill also automatically adds authentication to all messages sent through their servers, but adding SPF and DKIM records for your sending domain(s) is strongly recommended for better deliverability. You can do this by logging in to Mandrill and going to Settings->Domains to view and Test the DKIM and SPF instructions.

Receiving emails with Mandrill

To allow Mandrill to receive email on your behalf, log in to Mandrill and go to ‘Inbound’. If it is your first time using it, you will be asked to add a domain name first.

Once you add your domain, you will need to add 2 MX records to your domain name. This is to allow Mandrill to receive emails on your behalf. Press on ‘DNS settings’ for Mandrill to tell you the specific MX records to add. They will be in the format of :

xxxxxxx.in1.mandrillapp.com
xxxxxxx.in2.mandrillapp.com

To add these MX records, it depends on where you have purchased your domain name originally. Unfortunately, its outside of the scope of this guide to be able to give specific instructions for every hosting company, so in your own domain control panel, look for a DNS Settings section and add your MX records there. Once you have added your MX records, allow an hour or more for them to take effect and you can use the ‘Test’ button in Mandrill to make sure they are in place.

You can use a useful site http://mxtoolbox.com/ to check to see if your MX records are in place.

But what if I already have email DNS Records, such as Google apps set up on my domain?

This is a common scenario. It is likely that you already have some MX records in place for your business or personal emails and Mandrill’s new MX records won’t work well in this case.

To get around this, the solution is to create a new sub domain and add the MX records to that sub domain instead of the main domain name, so Mandrill doesn’t interfere with your regular emails.

For example, your normal emails could be using a domain name such as @domain.com. If you want to leave that alone for your personal or business emails, then set up a sub domain such as @app.domain.com. Notice the word ‘app’ that is now in the email address. The word can be anything you like, it is just a label of sorts to separate your normal emails from those that will be sent/received by your web application.

Once your MX records are in place..

The MX records allow Mandrill to receive emails. The next step is to to tell Mandrill what to do with those emails. The solution is to use ‘Routes’, this allows you to tell Mandrill where to send the emails it receives.

To create a new route, or edit existing ones, click on ‘Inbound’ and then click on ‘Routes’ next to the domain name you added earlier.

When adding a new route, you will be asked for the email address that you would like people to be able to email and also the URL to post to.

You can set the email address to ‘*’ to allow it to receive all emails to the domain name you have added, or else specify a particular email address if you prefer, such as ‘incoming@app.domain.com’.

You will then need to tell Mandrill the URL to send your email to. A useful site to see what information Mandrill will send to your application is http://requestb.in. This site gives you a temporary URL which you can add as a route and tell Mandrill to send some test emails to it to seem them.

Once you are ready, set the URL to something in your web application, such as : http://mydomain.com/recieve_mandrill_email.

How you process the incoming email depends on the programming language you are using.

Here is some PHP/Codeigniter code you can use as a starting point to receive incoming email.

https://github.com/murrion/mandrill-receive-email

 

20 Comments

  1. I have a problem and I cant find the solution. Is it possible to send emails from different users but same domain from Mandrill. I have 2 emails on the same domain and would like to be able to send from either. I use outlook. I cant find a way to make this work.

    Thanks.

    • Hi Carlos,

      Thanks for commenting.

      Once you have set up your domain name with Mandrill, then it should be fine to send out emails from any email address, within reason, from that same domain name, assuming you are using the correct Mandrill SMTP settings.

      I know a company using Mandrill for all their staff emails, regardless of their email client and its working well.

      Gordon.

  2. Is it possible for Mandrill Incoming messages handler to forward messages to my main used Gmail account instead of posting them through a POST request to a web script.

    My concern is due to possible downtimes to this POST endpoint due to the hosting company to which it’s uploaded. I prefer to rely on direct communication between two major companies such as Mandrill=>Gmail so my email is properly and reliably delivered to my most commonly used inbox when it’s sent to my corporate website (e.g. support@corporate.com). Naturally, I will set the MX records in corporate.com as per the Mandrill instructions.

    • Hi Dzhuneyt,

      Thanks for commenting.

      One of the main reasons you would use Mandrill, or Mailgun or another similar service is for your software to receive an email, instead of the email going in to a regular users email inbox.

      If you want your emails to go in to your inbox then you can just not use Mandrill at all and set up Forward rules in your recipients inbox.

      If you want an incoming email to be received by your software and also go to your Gmail inbox, then you could send the emails to Gmail first, and then set up Gmail to forward the email to your mandrill powered email address second for your software to receive it too.

      I hope this helps,

      Gordon.

  3. hi i have a free account . and 2 api’s , but i cannot work out , step by step how i actually send out a dozen emails , i cannot get to first base you might say .
    after i log in , what is the next step i must take , and the second etc , do you have simple step by step directions i must take in the web site ? , thank you don rees

  4. Hello Gordon,

    I am new to use these email facilities.

    My problem is that I have purchased domain name from one domain name registrar and hosting from another. My domain registrar provided free Email service. But that will work only with their SMTP server.

    My domain registrar’s smtp server is not working with my hosting company due to restriction from my registrar i.e. registrar says that hosting company should use only local host for email services which was not done from hosting company but hosting company says that it working well with Mandrill . So I tried with mandrill and its works well (Receiving mail from my web site to my Gmail mail ID using Mandrill after updating “My Domain name MX records with registrar”)

    The issue is that I am unable to use mail id with my own domain name bcz registrar email supports only their SMTP and MX records.

    I have searched that every one provides email id with my own domain name but I have to update their SMTP server details into my “domain Registrar” DNS MX record, if I do so mandrill won’t work.

    I need a solution? and can anyone provide email id in my own domain name without using their SMTP so that I can continue to use mandrill SMTP my site also will work.

  5. I’m a little unclear as to where the actual email list is stored in all this. Mandrill states they don’t store the list on their site. So where is it stored? In Mailchimp? If MC, if you load say 10K mails into their system, do you then need to pay for their monthly plan, then pay extra for your Mandrill sends?

    If the data resides outsides Mandrill, I guess not, but I’m unclear where it does reside and how Mandrill manages unsubscribes, bounces stats, etc.

    Any insight much appreciated!

    Rick Chapman
    Managing Editor and Publisher, Softletter
    Author: Selling Steve Jobs’ Liver. A Story of Startups, Innovation, and Connectivity in the Clouds”
    “In Search of Stupidity: Over 20 Years of High-Tech Marketing Disasters”
    “SaaS Entrepreneur: The Definitive Guide to Succeeding in Your Cloud Application Business”

    • Hi Rick, Thanks for reading the post and for commenting too.

      Mandrill and Mailchimp are developed by the same company, but they have different purposes.

      If you are an individual or a business and want to send newsletters to your subscribers, then you would use Mailchimp. Mailchimp gives you an interface to create and edit the content, as well as manage your email addresses and then give you information on the number of people that opened your newsletter too after sending it.

      Mandrill is more suitable for software developers, to give them an interface for sending emails automatically from their software product. To send them a welcome email once they have signed up to use their software product for example. Mandrill does not store the email addresses in this case, it just acts as a delivery service.

      Does that make sense?

  6. Hi Gordon ,will mandrill accept a format like this “example@gmail.com”@subdomain.com for inbound emails ?
    whereas my route is configured like this “*@subdomain.com”.Any workaround for this to work ?
    I guess mandrill is validating with single “@” symbol .So except @ if i use any other symbol it is working .

    • Hi Vinay,

      Thanks for commenting.

      Do you mean you want Mandrill to accept emails sent to : example@gmail.com@subdomain.com?

      I don’t think this will work. Even if Mandrill accepted it, its not a well structured email address so anyone trying to send emails to this address would probably have problems sending.

      If you need the public to see “example@gmail.com”, you could set up Gmail to forward the emails to something@subdomain.com in Mandrill if you wanted to. Does that make sense?

  7. Hi Gordon,

    Thank you for the post.

    I am quite out of my depth. I am considering the benefits of Mandrill for the useful reporting and stats benefits – click and open rates etc.

    What I would like to know is how emails are created and sent so that I can have access to the above mentioned reporting and stats through Mandrill?

    I know that we can create emails in Mailchimp and can export those templates to Mandrill. However, what is then used to send those templates?

    Hopefully i use the correct terminology. If Outlook can create the email, what is the email client used to send the email? Is there a current solution to create and send an email in Outlook and have click and open stats available for these emails through Mandrill?

    Appreciate any assistance.

    Regards,

    Evan

  8. Hi Gordon,

    Thank you for your write up. Mandrill has now made it mandatory to verify all outgoing and incoming domains. I set up my sending and incoming domain as “app.mydomain.com”. But since Mandrill now requires verification, it means that I have to be able to receive email on info@app.mydomain.com.

    We use Google apps for our main “mydomain.com” and the MX records are configured for the same. My question is, how to add MX records for app.mydomain.com? It’s weird since I’ve configured Mandrill to also receive (inbound) email for app.mydomain.com. If I configure G-apps to receive emails for the subdomain, it kind of negates the purpose of setting up Mandrill inbound MX records …

Leave a Reply

Your email address will not be published. Required fields are marked *