Updating Templates 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 update templates using the plugin.

Note: the request validation has been turned off in this example.

Example

Update Template Form
Template Name
From Email
From Name
Subject
HTML Content
Text Content
Publish?
Labels (Seperate multiple labels with a , )

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
{
//Update the template
EasyEmailForMandrill.MandrillTemplate.TemplateInformation template =
EasyEmailForMandrill.ManagingTemplates.TemplateFunctions.UpdateTemplate(
    txtTemplateName.Text,
    txtFrom.Text,
    txtName.Text,
    txtSubject.Text,
    txtHTML.Text,
    txtTextContent.Text,
    chkPublish.Checked,
    txtLabels.Text.Split(","[0]).ToList()
    );

//Show the response
lblOut.Text =
    "Updated Date of updated 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 updated. 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"
}