This page contains conceptual and procedural information about creating a triggered send email campaign using SOAP API.
Why Create a Triggered Send Email Campaign
A triggered send email campaign takes a previously created email message and sends that message out in response to an outside request, such as a subscriber opting in to receive the message.
How To Create a Triggered Send Email Campaign
Use the flow chart and sample code as an example of how to create and order the processes necessary for the triggered email send campaign.
Triggered Send Email Campaign Workflow Process
Sample Code
This section contains sample code you can use to conduct your triggered sends.
Sample .NET Code
1using System;2using System.Configuration;3using System.Data;4using System.Linq;5using System.Web;6using System.Web.Security;7using System.Web.UI;8using System.Web.UI.HtmlControls;9using System.Web.UI.WebControls;10using System.Web.UI.WebControls.WebParts;11using System.Xml.Linq;12using etAPI;13public partial class ETTriggeredSend : System.Web.UI.Page14{15 //Global Variables16 private SoapClient client = new SoapClient();17 protected void Page_Load(object sender, EventArgs e)18 {19 //Authenticate20 client.ClientCredentials.UserName.UserName = System.Configuration.ConfigurationSettings.AppSettings["wsUserName"];21 client.ClientCredentials.UserName.Password = System.Configuration.ConfigurationSettings.AppSettings["wsPassword"];22 if (!IsPostBack)23 {24 }25 }26 protected void btnSubmit_Click(object sender, EventArgs e)27 {28 try29 {30 //Create a GUID for ESD to ensure a unique name and customer key31 string strGUID = System.Guid.NewGuid().ToString();32 //Create TriggeredSendDefinition object [Messages > Email > Triggered]33 TriggeredSendDefinition tsd = new TriggeredSendDefinition();34 tsd.Name = "TSD_Name_" + strGUID;//required35 tsd.CustomerKey = strGUID;//recommended or the application assigns a number36 tsd.Description = "TSD_Description_" + strGUID;//recommended or the Description defaults to the Name37 //Set to delivery both Text and HTML versions.38 tsd.IsMultipart = true;//recommended as a best practice39 tsd.IsMultipartSpecified = true;//required40 //Set to track the links found in the email41 tsd.IsWrapped = true; //Enables tracking42 tsd.IsWrappedSpecified = true;//required43 //Create Email object to refer to pre-create Email44 Email em = new Email();45 em.ID = 620046; //required -- can be found at Content > My Emails > Properties46 em.IDSpecified = true;//required47 //Apply Email object to the TriggeredSendDefinition object48 tsd.Email = em;//required49 //Create SendClassification50 tsd.SendClassification = new SendClassification();51 tsd.SendClassification.CustomerKey = "4201";//required -- can be found at Setup > Send Management > Send Classifications > Edit Item > External Key52 //tsd.TriggeredSendType = TriggeredSendTypeEnum.Continuous;53 //tsd.TriggeredSendTypeSpecified = true;54 //tsd.TriggeredSendStatus = TriggeredSendStatusEnum.New;55 //tsd.TriggeredSendStatusSpecified = true;56 //tsd.BatchInterval = 1;57 //tsd.BatchIntervalSpecified = true;58 //tsd.AutoAddSubscribers = true;59 //tsd.AutoAddSubscribersSpecified = true;60 //tsd.AutoUpdateSubscribers = true;61 //tsd.AutoUpdateSubscribersSpecified = true;62 //tsd.List = list;63 string cRequestID = String.Empty;64 string cStatus = String.Empty;65 try66 {67 //Call the Create method on the TriggeredSendDefinition object68 CreateResult[] cResults = client.Create(new CreateOptions(), new APIObject[] { tsd }, out cRequestID, out cStatus);69 //Display Results70 lblMessage.Text += "Overall Create Status: " + cStatus;71 lblMessage.Text += "<br/>";72 lblMessage.Text += "Number of Results: " + cResults.Length;73 lblMessage.Text += "<br/>";74 //Loop through each object returned and display the StatusMessage75 foreach (CreateResult cr in cResults)76 {77 lblMessage.Text += "Status Message: " + cr.StatusMessage;78 lblMessage.Text += "<br/>";79 }80 }81 catch (Exception exCreate)82 {83 //Set Message84 lblMessage.Text += "<br/><br/>CREATE TSD ERROR:<br/>" + exCreate.Message;85 }86 //Preceed if the above Create call was successful87 if (cStatus == "OK")88 {89 // *** MAKE TRIGGERED SEND DEFINITION ACTIVE90 tsd = new TriggeredSendDefinition();91 tsd.CustomerKey = strGUID;//required92 tsd.TriggeredSendStatus = TriggeredSendStatusEnum.Active;//necessary to set the TriggeredSendDefinition to "Running"93 tsd.TriggeredSendStatusSpecified = true;//required94 string uRequestID = String.Empty;95 string uStatus = String.Empty;96 try97 {98 //Call the Create method on the EmailSendDefinition object99 UpdateResult[] uResults = client.Update(new UpdateOptions(), new APIObject[] { tsd }, out uRequestID, out uStatus);100 //Display Results101 lblMessage.Text += "Overall Update Status: " + uStatus;102 lblMessage.Text += "<br/>";103 lblMessage.Text += "Number of Results: " + uResults.Length;104 lblMessage.Text += "<br/>";105 //Loop through each object returned and display the StatusMessage106 foreach (UpdateResult ur in uResults)107 {108 lblMessage.Text += "Status Message: " + ur.StatusMessage;109 lblMessage.Text += "<br/>";110 }111 }112 catch (Exception exCreate)113 {114 //Set Message115 lblMessage.Text += "<br/><br/>UPDATE TSD ERROR:<br/>" + exCreate.Message;116 }117 //Preceed if the above Update call was successful118 if (uStatus == "OK")119 {120 // *** SEND THE TRIGGER EMAIL121 //Create a new Subscriber to send the Trigger to122 Subscriber newSub = new Subscriber();123 newSub.EmailAddress = "acruz@exaple.com";124 newSub.SubscriberKey = "acruz@exaple.com";125 //Create Subscriber Attributes126 newSub.Attributes = new etAPI.Attribute[2]; //Can be found at Subscribers > Profile Management127 //1128 newSub.Attributes[0] = new etAPI.Attribute();129 newSub.Attributes[0].Name = "FromName";//Account Specific130 newSub.Attributes[0].Value = "From John Doe";//Subscriber Specific131 //2132 newSub.Attributes[1] = new etAPI.Attribute();133 newSub.Attributes[1].Name = "HTML__Content";//Account Specific134 newSub.Attributes[1].Value = "This is a test <a href=\"httpgetwrap|http://google.com\" alias=\"Google Link\">link</a>"; //httpgetwrap| must be before the http for tracking to work135 //Create a new Subscriber to send the Trigger to136 Subscriber newSub2 = new Subscriber();137 newSub2.EmailAddress = "jdoe@example.com";138 newSub2.SubscriberKey = "jdoe@example.com";139 //Create Subscriber Attributes140 newSub2.Attributes = new etAPI.Attribute[2];//Can be found at Subscribers > Profile Management141 //1142 newSub2.Attributes[0] = new etAPI.Attribute();143 newSub2.Attributes[0].Name = "FromName";//Account Specific144 newSub2.Attributes[0].Value = "From Angela Cruz";//Subscriber Specific145 //2146 newSub2.Attributes[1] = new etAPI.Attribute();147 newSub2.Attributes[1].Name = "HTML__Content";//Account Specific148 newSub2.Attributes[1].Value = "This is a test <a href=\"httpgetwrap|http://example.com\" alias=\"ET Link\">link</a>"; //httpgetwrap| must be before the http for tracking to work149 //Create a TriggeredSend object to referrence the earlier created TriggeredSendDefinition150 TriggeredSend ts = new TriggeredSend();151 ts.TriggeredSendDefinition = new TriggeredSendDefinition();152 ts.TriggeredSendDefinition.CustomerKey = strGUID;//This is the External Key from the UI153 ts.Subscribers = new Subscriber[] { newSub, newSub2 };//Add the Subscriber objects to the TriggeredSend object154 string tsRequestID = "";155 string tsStatus = "";156 try157 {158 //Call the Create method on the TriggeredSend object159 CreateResult[] tsResults = client.Create(new CreateOptions(), new APIObject[] { ts }, out tsRequestID, out tsStatus);160 //Display Results161 lblMessage.Text += "Overall Update Status: " + tsStatus;162 lblMessage.Text += "<br/>";163 lblMessage.Text += "Number of Results: " + tsResults.Length;164 lblMessage.Text += "<br/>";165 //Loop through each object returned and display the StatusMessage166 foreach (CreateResult tscr in tsResults)167 {168 lblMessage.Text += "Status Message: " + tscr.StatusMessage;169 lblMessage.Text += "<br/>";170 }171 }172 catch (Exception exCreate)173 {174 //Set Message175 lblMessage.Text += "<br/><br/>CREATE TS ERROR:<br/>" + exCreate.Message;176 }177 }178179 }180 catch (Exception exc)181 {182 //Set Message183 lblMessage.Text += "<br/><br/>###ERROR<br/>" + exc.Message;184 }185 }186}
SOAP Envelopes to Interact with Emails and Triggered Send Definitions
This section includes sample code you can use to create a triggered email send using the SOAP API.