Send email in django project with mandrill service

To send email messages from server we can just use SMTP protocol. But there is another way - special email services. I’ll describe one of them here, mandrill.com.

Advantages

  • Detailed statistic of sent emails. How many were sent, to whom, when. How many were opened, what links were clicked.
  • Message templates. They can be modified through mandrill service, no need to create anything in django admin. It is possible to use variables in templates, set subject, even address of sender. In django application you just specify the template name and the context (variables).
  • No need of your own mail service. And no need to enable you domain in google/yandex mail (but still it will be useful).
  • Free plan, that allows to send 12000 messages per month.

Disadvantages

  • For click statistic all links in you email will be replaced by special redirect urls. Probably regular users will not mention that.
  • In some mail clients (for example gmail in browser) the field ‘sender’ along with specified address will contain the real address of mandrill. But it is possible to set DKIM and SPF DNS records for your domain, so sender address will be correctly shown everywhere.
  • If you want to send more than 12000 messages per month, you need to buy corresponding plan.

To my mind, advantages are greater than disadvantages.

Integration

  1. Register on https://mandrill.com/signup/

  2. Create API_KEY:

Create API_KEY step 1

Create API_KEY step 2

Create API_KEY step 3


  1. Create message template:

Create message template step 1

Create message template step 2

3.1. Set template name (for example template-1):

Set template name


  1. Edit the template contents:

Edit the template contents

Statistic example

  1. Time send graph:

ГTime send graph


  1. Message open and link clicks graph:

Message open and link clicks graph


  1. List of all sent messages:

List of all sent messages


  1. Link statistic:

Link statistic


Django integration

Gist contains example of integration with django and also standalone usage in python script.