Email Server-Side JavaScript Functions

From $1

    This document contains conceptual, procedural, and scenario information regarding the use of the Email Server-side JavaScript functions.

    Why Use the Email Server-Side JavaScript Functions

    These functions allow you to access and control email messages within your ExactTarget account.

    Scenario

    Northern Trail Outfitters wants to update the subject line of their weekly email to include the date the email was sent. They use server-side JavaScript to initialize the email and use the Update() function to change the subject.

    How to Use the Email Server-Side JavaScript Functions

    In your server-side JavaScript code, first load the core library using the syntax below:

    Platform.Load("core", "1");

    Initialize

    To interact with an email via server-side JavaScript, you must first initialize the object. The code below initializes an email with the external key of 'myEmail'.

    var myEmail = Email.Init("myEmail");

    Once you initialize the email, you can use the remaining functions contained on this page.

    Add(email)

    This function adds a new email to your account and returns an initialized object.

    Arguments

    • email - a JSON object representing the properties of the new email

    The sample code below adds an email to your account:

    var newMail = {
        "CustomerKey" : "test_email_key",
        "Name" : "Test Email",
        "CategoryID" : "",
        "HTMLBody" : "<b>This is a test email</b>",
        "TextBody" : "This is a test email",
        "Subject" : "Test Email Subject",
        "IsActive" : "true",
        "IsHTMLPaste" : "true",
        "Status" : "active",    
        "EmailType" : "HTML",
        "CharacterSet" : "US-ASCII",
        "HasDynamicSubjectLine" : "false"
    };
    var myEmail = Email.Add(newMail);

    Remove()

    This function removes a previously initialized email.

    The sample code below deletes the email with the external key myEmail:

    var myEmail = Email.Init("myEmail");
    myEmail.Remove();

    Retrieve(filter)

    This function retrieves an array of emails based on the specified criteria.

    Arguments

    • filter - The criteria on which to search for the email

    The sample code below retrieves an array of emails based on the specified criteria:

    var results = Email.Retrieve({Property:"CustomerKey",SimpleOperator:"equals",Value:"myEmail"});

    Update(attributes)

    This function updates the email and returns a status.

    Arguments

    • attributes- attributes regarding the email to be changed.

    The sample code below updates the Name and Subject attributes of the email to the specified value:

    var myEmail = Email.Init("myEmail");
    var status = myEmail.Update({ "Name": "Updated Name", "Subject" : "Updated Email Subject" });

    CheckContent()

    This function runs content checks on the initialized email (similar to the Content Detective tool) and returns a JSON object indicating the result of the content check and any identified issues.

    The following code calls CheckContent() on the initialized email object and writes out the results from the returned JSON object:

    var myEmail = Email.Init("myEmail");
    var results = myEmail.CheckContent();
    Write(results.Task.CheckPassed);
    Write(results.Task.ResultMessage);

    Validate()

    This function runs validation checks on the initialized email and returns a JSON object indicating the result of the validation and any identified issues.

    The following code calls Validate() on the initialized email object and writes out the results from the returned JSON object:

    var myEmail = Email.Init("myEmail");
    var results = myEmail.Validate();
    Write(results.Task.ValidationStatus);
    Write(results.Task.ValidationMessages);

    This page was last updated by Ryan Williams on Tue, 13 Sep 2011 11:01:14 GMT.

    If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:

     


    Was This Page Helpful?
    Suggestions or Comments:
    Name (optional):
    Email Address (optional):
    Enter 20680 backwards:
       
    Tags: (Edit tags)
    • No tags
     
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch 2010
    Admin