Sending an ExactTarget triggered email.

Screen grabs to come...

Assuming you have your account set up to use the API, the steps and code below should get you going. This also assumes you are starting a fresh project - I've read there is an order to installing WSE and making reference to the WDSL.

  1. Install Web Services Enhancements (WSE) 3.0 for Microsoft .NET
  2. Start new website/project in Visual Studio.
  3. I don't have it in front of me right now, but you need to right click on either the project or site and enable WSE.
  4. Create a web reference to: https://webservice.exacttarget.com/etframework.wsdl
  5. Log in to your ExactTarget account and create an email: content->my emails->create
  6. In the ExactTarget app, select interactions->emails->triggered->create and point to the email you created in step #5 - the External Key is can be anything you want - as long as it does not match another Triggered External Key - It does need to match the External Key below. The subject line and message body can be dynamic if in the ExactTarget app you add:  subscribers->profile management-> "SubjectLine" and "HTML__Body".
  7. See below:
/* add these */
using System.Web.Services.Protocols;
using Microsoft.Web.Services3.Design;
using Microsoft.Web.Services3.Security.Tokens;
using com.exacttarget.webservice;

public partial class myPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        sendTriggeredEmail
        (
             "jim.smith@gmail.com",
             "jim smith",
             "scott.anderson@yahoo.com",
             "Test subject line",
             "Test message body"        );
    }

    private void sendTriggeredEmail(string from,string fromName, string to, string subject, string message)
    {
        PartnerAPIWse apiCall = new PartnerAPIWse();
        UsernameTokenProvider utp = new UsernameTokenProvider("your api key", "your api password");
        apiCall.SetClientCredential(utp.GetToken());
        Policy policy = new Policy(new UsernameOverTransportAssertion());
        apiCall.SetPolicy(policy);

        apiCall.EnableDecompression = true;

        TriggeredSendDefinition tsd = new TriggeredSendDefinition();
        tsd.CustomerKey = "External Key - defined in the ExactTarget Application";
        TriggeredSend ts = new TriggeredSend();
        ts.TriggeredSendDefinition = tsd;
        ts.Subscribers = new Subscriber[1];
        ts.Subscribers[0] = new Subscriber();
        ts.Subscribers[0].EmailAddress = to;
        ts.Subscribers[0].SubscriberKey = to;

        ts.Subscribers[0].Owner = new Owner();
        ts.Subscribers[0].Owner.FromAddress = from;
        ts.Subscribers[0].Owner.FromName = fromName;

        ts.Subscribers[0].Attributes = new com.exacttarget.webservice.Attribute[2];

        ts.Subscribers[0].Attributes[0] = new com.exacttarget.webservice.Attribute();
        ts.Subscribers[0].Attributes[0].Name = "SubjectLine";
        ts.Subscribers[0].Attributes[0].Value = subject;

        ts.Subscribers[0].Attributes[1] = new com.exacttarget.webservice.Attribute();
        ts.Subscribers[0].Attributes[1].Name = "HTML__Body";
        ts.Subscribers[0].Attributes[1].Value = message;

        string status = null;
        string requestID = null;
        CreateResult[] results = apiCall.Create(
            new CreateOptions(), 
            new APIObject[] { ts }, 
            out requestID, 
            out status
        );
        Response.Write("results[0].StatusCode: " + results[0].StatusCode + "\n");
        Response.Write("results[0].StatusMessage: " + results[0].StatusMessage + "\n");
    }
}
 
View Scott Peterson's profile on LinkedIn Scott Peterson Minneapolis on Facebook Follow Scott Peterson on Twitter.com Read blog posts by Scott Peterson Minneapolis Resume of Scott Peterson Minneapolis Scott Peterson Minneapolis on Society of Digital Agencies