Tuesday, November 29, 2011

How to track transactional emails all the way through using the SMTP relay

There may be cases where, using the SMTP relay, you want to programatically track the status of every transactional email sent.  At first thought, this seems difficult, since when sending via the SMTP relay, you can't retrieve an ID for each email like you can by calling the API method SendTransactionalEmail, which does return a unique ID for each email sent.

To get around this, you can insert a custom unique ID header into your SMTP relay messages, and use that custom unique ID to track your transactional emails all the way through.

For example, let's say you insert the header X-MyCustomID into every email you send via the SMTP server.  And for each email, you use a different value for X-MyCustomID.  Your first ten transactional emails would have these headers:

X-MyCustomID: 1

X-MyCustomID: 2

X-MyCustomID: 3

...and so on.

Step 1:

Tell JangoSMTP what the header is that is storing your custom ID.  Do this under Settings --> Tracking --> General:

Step 2:

Send your emails via the relay inserting the header into every email you send, and in your own system, keep track of all custom IDs used.

Step 3:

Call this API method with each custom ID.  This method will allow you to retrieve the JangoSMTP assigned ID based on your own custom ID.

  • GetTransactionalIDsFromCustomID
    Retrieves the system transactional ID given a user-specified custom ID for a transactional email. Returns an XML Document.

  • Once you have the JangoSMTP assigned ID, you can call any number of methods to get the status of your transactional email, such as:

  • Reports_Transactional_GetSingleEmailStats_Dataset
    Retrieves statistics for a transactional email. Returns a .NET DataSet.

  • Reports_Transactional_GetSingleEmailStats_String
    Retrieves statistics for a transactional email. Returns a string.

  • Reports_Transactional_GetSingleEmailStats_XML
    Retrieves statistics for a transactional email. Returns an XML document.