Mandrill Template Example

Mandrill templates allow you to quickly create a professional template and customise each email you send based on that template.

You can read more about Mandrill templates by visiting the Mandrill support website found here.

Customising your templates can be done by adding content in the following three ways. Examples of all are below.

Editable Sections

By adding the attribute mc:edit="EditableSectionName" you can then add a TemplateContent with that name and the content you wish to inject when creating a template object.

Merge Tags

By adding *|MergeTagName|* to your template you can then add a merge tag to your email to replace the tag with your own content.

Merge Tags can be Global which means it will replace the Merge Tag in all emails or you can specify a normal Merge Tag with a recipient to replace the tag with that content for that person.

For example you may want to use a Global Merge Tag to say which month the email is for but set a merge tag for each recipient with their name.


Contact Form

Step By Step

Step 1

First you need to follow the guide for integrating the DLL and setting up Easy Email at Setting Up.

Next all that is required is the below code, placed inside the click handler of the send button.

//Create the recipient
EasyEmailForMandrill.Recipient recipient =
new EasyEmailForMandrill.Recipient(txtTo.Text);

//Create the Template Contents
List<EasyEmailForMandrill.MandrillTemplate.TemplateContent> TemplateContents = 
new List<EasyEmailForMandrill.MandrillTemplate.TemplateContent>();
//Add some content to the Template Contents
    new EasyEmailForMandrill.MandrillTemplate.TemplateContent("ajtest", 
    new EasyEmailForMandrill.MandrillTemplate.TemplateContent("footer", 
                                                              "test footer EE"));
//Create a Template
EasyEmailForMandrill.MandrillTemplate.Template template =
    new EasyEmailForMandrill.MandrillTemplate.Template("Example Template", 

//Now we create the EasyEmail object
EasyEmailForMandrill.MandrillEmail email =
    new EasyEmailForMandrill.MandrillEmail(
        txtSubject.Text, template);

//Create some global merge vars
email.AddGlobalMergeVar("global1", "Text for global1");
email.AddGlobalMergeVar("global2", "Text for global2");

//Add some merge vars for person 1
email.AddMergeVar(txtTo.Text, "merge1", "Person1 Text for merge1");
email.AddMergeVar(txtTo.Text, "merge2", "Person1 Text for merge2");

//Add some merge vars for person 2
email.AddMergeVar("", "merge1", "Person2 Text for merge1");
email.AddMergeVar("", "merge2", "Person2 Text for merge2");

//We then send the email and get a EasyEmailResponse back
EasyEmailForMandrill.EasyEmailResponse response = email.Send();

//Finally we display the EasyEmailResponse message
lblOut.Text = "Easy Email response : " + response.Message;


That's all you need to do to send an email from a template with Easy Email For Mandrill