Sunday, July 17, 2011

How to use the SendTransactionalEmailRaw API method


The SendTransactionalEmailRaw method is a special API method that allows you to send a transactional email, but requires you to assemble a MIME compliant message body on your own. By contrast, the more common method, SendTransactionalEmail, need only an HTML body, a Plain Text body, and optional attachments, and then the API will assemble the MIME-formatted message automatically for transmission to the recipient.

SendTransactionalEmailRaw is the method that is used behind-the-scenes by our SMTP relay service. Anytime a user relays a message to, our code internally calls SendTransactionalEmailRaw. This method was originally developed just for our internal use to enable our SMTP relay, but since it appears in our full method listing, our clients have begun inquiring about how they too can use it, and that's why we are publishing this article.


In this article, we'll look at examples of manually assembled MIME parts and how to submit the raw message to this method.

First, let's look at the input parameters of the method. Some should be self-explanatory, so we won't include explanations of those here.

Options: This input value represents the same as for the SendTransactionalEmail method, so we won't cover them here. Here you can set options like open tracking, click tracking, a custom reply-to address, and much more. For more info on the Options parameter, see

ToEmailAddress: This is the email address that will receive this message.

ToHeader: This is the email address that will show in the To header of the email message, which technically doesn't have to be the recipient of the message. It is important to distinguish between ToHeader and ToEmailAddress. In most business cases, these will be the same email address and therefore the same value. If I want to send an email to, then and, because I want the To header to show the same email address to which the message was sent.

Scenarios where the To header and the receiving email address differ include situations when CC and BCC are used. If I send an email to and BCC, then in the background, two distinct emails are actually being transmitted:

1. and
2. and

Content-Type: This is the RFC 2045 Content-Type header of the email message.

Example values are:
  1. text/plain
  2. text/html
  3. multipart/alternative; boundary="----=_NextPart_000_2424_01CA056C.1610FF60"
RawMessage: This is the pre-assembled MIME message and is closely related to the value for Content-Type. If Content-Type is text/plain, then the value for RawMessage could be any plain text message:

Example 1

Content-Type: text/plain
This is a simple plain text message.

Example 2

Here's an example of a body with both HTML and Plain text message parts.

multipart/alternative; boundary="------------020009050405090403020909"

Example 3

Lastly, here's an example of a plain text message with an attachment.

Content-Type: multipart/mixed;

Test Form:

You can experiment with the method using the test form at This form has textareas instead of text fields for those input parameters that warrant them, making it easier to test than the API-generated page at

Lastly, here is a screenshot of the test form filled out for the third example (plain text message with attachment), so you can see exactly how the method would be called: