'Madrill Transactional Email

I want to us mandrill's API to send transactional email. Found this to endpoint /messages/send and /messages/send-template. The /messages/send is straight forward just need to supply the html for the email body. However the html seems too complicated and we want to store it as template. Found this documentation https://mailchimp.com/developer/transactional/api/messages/send-using-message-template/ however the example is to vague. Not sure about the difference between the template_name and the template_content. The template_content also have the name and content parameters and I'm not sure where to get them since they are required.



Solution 1:[1]

I totally agree that the Mandrill's reference documentation is poor (not to mention that the API doesn't have any helpful error feedback). There's a dedicated section in Mandrill's documentation which covers templates and dynamic content, but it's long-winded, so let's get straight to the point:

  • template_name identifies the template; it corresponds to the "Template Slug" value you fill in when creating a template in Mandrill (at https://mandrillapp.com/templates)
  • template_content is an array of objects like {"name": "", "content": ""}, where name identifies the variable in the template, and content is the value to be used.

So, the payload may look for example like this:

{
  "key": "<your api key>",
  "template_name": "template-slug",
  "template_content": [
    {"name": "variable1", "content": "Value inserted for variable1"},
    {"name": "variable2", "content": "Value inserted for variable2"},
  ],
  "message": {
    "subject": "Email subject",
    "to": [{"email": "[email protected]"}],
  }
}

(This is sent as POST to https://mandrillapp.com/api/1.0/messages/send-template.)

We have recently implemented sending of template emails with simpler interface in Superface. In addition to Mailchimp/Mandrill it also supports other email providers like SendGrid and Mailgun, so if you are using Node.js, perhaps you will find it useful. [Disclaimer: I work at Superface]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1