Mandrill: Send transactional emails from Drupal

By
César Álvarez's picture
César Álvarez
· 19/07/2015

Email is one of the most powerful tool for a website for enhancing customer service and increasing brand loyalty in all regards.

If they’re used in the right way, transactional emails can improve the user’s experience, immediately arriving with the website’s and brand’s design style.

What are transactional emails?

Well, they aren’t newsletters or any other type of email. They’re sent on an individual basis because of a user’s action (or inaction) and act like notifications.

Examples of transactional emails include the typical user registration email, password reminders from Badoo, order confirmation of a plane ticket to Marrakesh, wall posts from Francis on Facebook, profile visits from Lucy on LinkedIn, notifications you have joined an S&M group in your neighborhood, etc…

If at some point you’ve had problems sending these types of emails from your site and your users can’t get them, or they go directly to the Spam folder, it’s probably because your server has been blacklisted as spam.

Most of the time it’s because the server has been hacked and has become part of a zombie network that’s used for spamming.

When this happens, antispam systems add the server’s IP address to a blacklist, and all the connected websites are affected too.

To fix this problem, you have to use an external SMTP service to send transactional emails. These services guarantee your emails’ quick delivery.

Users demand immediacy, and email delays will noticeably hurt the user’s experience.

In Drupal, we can configure an SMTP server to send emails using the smtp module. But we can also use an external platform that specializes in this. Some of the most popular are MailjetAmazon SES, and Mandrill, but there are many more. Socialcompare has made a comparative list of transactional email services.

Here at Wild Wild Web, we recommend you use Mandrill, the transactional email sending service from Mailchimp which can send up to 12,000 email per month for free and has fantastic integration with Drupal.

If your website requires a larger volume of emails, there are also paid options.

About Mandrill

  • SPF and DKIM support that guarantees the emails aren’t marked as Spam
  • Globally distributed infrastructure with servers in 5 continents which reduces latency
  • Extensive email delivery statistics: openings, custom tagging, etc…
  • Template system for personalizing emails
  • Android and iOS apps
  • Much more…

Installing Mandrill into Drupal

In order to install and configure Mandrill into Drupal, follow the following steps:

1. Download and install the modules:
Mailsystem
Mandrill


2. Download the Mandrill PHP API library installer and upload it to the folder /sites/all/libraries/mandrill


 

3. Activate the Mandrill, Mandrill Reports, and Mandrill Template modules


4. Create an account at mandrillapp.com


5. Get an API Key for your account


6. Put the API Key into the Drupal configuration screen and save it


 

7. Do some final adjustments to the module’s configuration
Check the preferences for tracking or Google Analytics integration to track emails this way.

Once this configuration is done, send a test email using (surprise) Send Test Email in order to see if it all works right.

Now Drupal sends emails through Mandrill, but the results are only plain text… We’re back in the 90’s!
 

8. Make a template in Mandrill
In order for emails to be branded with the logo and colors of your brand, we need to make a custom template.

In your mandrillapp account, go to Outbound – Templates and hit Create a Template.


While editing a new template, you just have to paste the HTML that you want to use for your email and use the Email Template Language from Mailchimp in order to tell Mandrill which part of the email is dynamic.

It should be something like this:

<body bgcolor="#202020" style="margin: 0;padding: 0;">
<table bgcolor="#202020" width="100%">
<tr>
 <td>    
   <center>

… HTML for customized email …

  <div mc:edit="main" style="color:#000000;"></div>

… HTML for customized email …

</center>  
</td>
</tr>
</table>
</body>

The key is the tag <div mc:edit="main" style="color:#000000;"></div> which separates the body of the email from the rest.


9. Create a mapping template in Drupal
In order for Drupal to understand the new Mandrill template, you have to create a new Mandrill Template Map from admin/config/services/mandrill/templates, creating a name, selecting the template name and the region. Also, you have to select the Email Key that you want, which will usually be Site-wide Default.

 

Conclusions

Transactional emails are very important in improving user experience so you need to guarantee that their delivery will be rapid by using third-party tools.

Mandrill is a fantastic application for sending transactional emails from Drupal because it offers 12,000 free emails, is a well-developed application, and has great integration with our favorite CMS (Content Management System).

Share 
How can we help?Get in touch