Skip to main content

Sending Email Messages with Multiple Content Types

The content array in the API payload allows you to send the body of your message in multiple different formats, such as plain text and HTML. The recipient's email client will render the message using the content type that best fits their environment.

Behind the scenes, when you use the content array, we will encode your email message using the multipart/alternative mechanism.

Here's what the content array looks like:

"content": [
{
"type": content_type1,
"value": content1
},
{
"type": content_type2,
"value": content2
},
...
]

Each type must be a valid MIME type. A list of MIME content types that are generally readable in most email clients can be found below.

  • Plain Text: text/plain (note that text/plain must come first if you use it)
  • HTML: text/html
  • Rich Text: text/richtext
  • CSS: text/css
warning

MailChannels may reject messages with invalid or prohibited content types.

Sending Plain Text and HTML

The most common combination of content types is text/plain and text/html. Nearly all messages you send should be encoded in both of these types, with the plain text type appearing first.

Here's an example to illustrate how you can use the content array to send plain text and HTML content:

{
"personalizations": [
{
"to": [
{
"email": "recipient@example.com",
"name": "Recipient Name"
}
]
}
],
"from": {
"email": "sender@example.com",
"name": "Sender Name"
},
"subject": "HTML Email Test",
"content": [
{
"type": "text/plain",
"value": "This is the plain text version of the email."
},
{
"type": "text/html",
"value": "<html><body><h1>Hello,</h1><p>This is the HTML version of the email.</p></body></html>"
}
]
}
tip

For optimal deliverability, when using multipart/alternative, ensure the content of both versions conveys the same information for compatibility across email clients.

Prohibited MIME Types

The following MIME types are prohibited because they are frequently associated with abusive activity, such as malware sending. Specifying them in the content array will generate an error:

"application/x-msdownload"
"application/vnd.ms-htmlhelp"
"application/java-archive"
"application/x-sh"
"application/x-shellscript"

Other MIME types may also be prohibited from time to time if our automated abuse prevention systems detect ongoing abuse in relation to that MIME type.