Get Template Example

Templates are a useful tool to use with Mandrill, they will allow you to send the same email to multiple recipients whilst customising the content.

You can set templates up on Mandrill's website but you can also use Easy Email For Mandrill, this example will show you how to retreive templates from Mandrill using the plugin.

Example

Get Template Form
Template Name

Step By Step

Step 1

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

Step 2

Next add the following code to the click event of your create button, or wherever you want to create your template from

try
{
//Create the template
EasyEmailForMandrill.MandrillTemplate.TemplateInformation template =
EasyEmailForMandrill.ManagingTemplates.TemplateFunctions.GetTemplate(
    txtTemplateName.Text
    );

//Show the response
lblOut.Text =
    "Updated Date of template: " + template.UpdatedDate;
}
catch (Exception exception)
{
    //Handle the error
    lblOut.Text = "Error: " + exception.Message;
}

Step 3

A class will be returned with the information about the template you just published. It will contain the following information.

{
    "slug": "example-template",
    "name": "Example Template",
    "labels": [
        "example-label"
    ],
    "code": "<div mc:edit=\"editable\">editable content</div>",
    "subject": "example subject",
    "from_email": "from.email@example.com",
    "from_name": "Example Name",
    "text": "Example text",
    "publish_name": "Example Template",
    "publish_code": "<div mc:edit=\"editable\">different than draft content</div>",
    "publish_subject": "example publish_subject",
    "publish_from_email": "from.email.published@example.com",
    "publish_from_name": "Example Published Name",
    "publish_text": "Example published text",
    "published_at": "2013-01-01 15:30:40",
    "created_at": "2013-01-01 15:30:27",
    "updated_at": "2013-01-01 15:30:49"
}