Skip to main content

Content types

The content array contains the body of your email. Each entry is a {type, value} object, where type is a MIME content type and value is the body for that type. When you supply more than one entry, MailChannels encodes the message as multipart/alternative.

Plain text and HTML

Every message that includes a text/html part should include a text/plain part as well, with the plain text part first.
#!/usr/bin/env bash
set -u
: "${MAILCHANNELS_API_KEY:?Set MAILCHANNELS_API_KEY before running}"
: "${FROM_EMAIL:?Set FROM_EMAIL (must be on a Domain-Lockdown-authorized domain)}"
: "${TO_EMAIL:?Set TO_EMAIL}"

curl -X POST https://api.mailchannels.net/tx/v1/send \
  -H "Content-Type: application/json" \
  -H "X-Api-Key: $MAILCHANNELS_API_KEY" \
  -d @- <<JSON
{
  "personalizations": [
    { "to": [{ "email": "$TO_EMAIL", "name": "Recipient" }] }
  ],
  "from": {
    "email": "$FROM_EMAIL",
    "name": "Your Name"
  },
  "subject": "Hello from MailChannels",
  "content": [
    {
      "type": "text/plain",
      "value": "Hello from MailChannels."
    },
    {
      "type": "text/html",
      "value": "<p>Hello from <strong>MailChannels</strong>.</p>"
    }
  ]
}
JSON
Significant differences between the plain text and HTML versions hurt deliverability. Make sure the plain text version is the same message as the HTML version, just without formatting. It should contain all the same text, links, and images.

Supported MIME types

The following types are generally readable in most email clients:
  • text/plain
  • text/html
  • text/richtext
  • text/css
When multiple parts are present, the rendered body orders them as text/plain, then text/html, then any other types.

Prohibited MIME types

The following types are blocked because they are frequently associated with malware delivery. Including them in content returns an error:
  • application/x-msdownload
  • application/vnd.ms-htmlhelp
  • application/java-archive
  • application/x-sh
  • application/x-shellscript
Other MIME types may be blocked from time to time when our abuse-prevention systems detect ongoing abuse involving that type.