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
-
Register on https://mandrill.com/signup/
-
Create API_KEY:
- Create message template:
3.1. Set template name (for example template-1):
- Edit the template contents:
Statistic example
- Time send graph:
- Message open and link clicks graph:
- List of all sent messages:
- Link statistic:
Django integration
Gist contains example of integration with django and also standalone usage in python script.