> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mailchannels.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Content types

> Learn about the content types you can use in your email body and how to use them effectively.

## Creating the email body

The `content` array contains the body of your email. Each entry is a `{type, value}` object, where `type` is a
[MIME](https://datatracker.ietf.org/doc/html/rfc2045) 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.

<CodeGroup>
  ```bash cURL theme={null}
  #!/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
  ```

  ```javascript Node.js theme={null}
  import { MailChannels } from "mailchannels-sdk";

  const { MAILCHANNELS_API_KEY, FROM_EMAIL, TO_EMAIL } = process.env;
  if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
  if (!FROM_EMAIL) throw new Error("Set FROM_EMAIL (must be on a Domain-Lockdown-authorized domain)");
  if (!TO_EMAIL) throw new Error("Set TO_EMAIL");

  const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);

  const { data, error } = await mailchannels.emails.send({
    from: { email: FROM_EMAIL, name: "Your Name" },
    to: { email: TO_EMAIL, name: "Recipient" },
    subject: "Hello from MailChannels",
    text: "Hello from MailChannels.",
    html: "<p>Hello from <strong>MailChannels</strong>.</p>",
  });

  if (error) {
    console.error("Send failed:", error);
    process.exit(1);
  }
  console.log(data);
  ```

  ```python Python theme={null}
  import os
  import sys

  import mailchannels

  if not os.environ.get("MAILCHANNELS_API_KEY"):
      sys.exit("Set MAILCHANNELS_API_KEY before running")

  from_email = os.environ.get("FROM_EMAIL")
  to_email = os.environ.get("TO_EMAIL")
  if not from_email:
      sys.exit("Set FROM_EMAIL (must be on a Domain-Lockdown-authorized domain)")
  if not to_email:
      sys.exit("Set TO_EMAIL")

  # Passing both text and html sends a multipart/alternative message; clients
  # pick the best part they can render.
  response = mailchannels.Emails.send(
      {
          "from": {"email": from_email, "name": "Your Name"},
          "to": [{"email": to_email, "name": "Recipient"}],
          "subject": "Hello from MailChannels",
          "text": "Hello from MailChannels.",
          "html": "<p>Hello from <strong>MailChannels</strong>.</p>",
      }
  )

  print(response)
  ```

  ```php PHP theme={null}
  <?php

  require_once __DIR__ . '/vendor/autoload.php';

  use MailChannels\Client;

  $api_key    = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
  $from_email = getenv('FROM_EMAIL') or exit("Error: FROM_EMAIL is not set\n");
  $to_email   = getenv('TO_EMAIL') or exit("Error: TO_EMAIL is not set\n");

  $client = new Client(apiKey: $api_key);

  // Passing both text and html sends a multipart/alternative message; clients
  // pick the best part they can render.
  $response = $client->emails->send([
      'from'    => ['email' => $from_email, 'name' => 'Your Name'],
      'to'      => ['email' => $to_email, 'name' => 'Recipient'],
      'subject' => 'Hello from MailChannels',
      'text'    => 'Hello from MailChannels.',
      'html'    => '<p>Hello from <strong>MailChannels</strong>.</p>',
  ]);

  print_r($response->toArray());
  ```
</CodeGroup>

<Tip>
  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.
</Tip>

### Supported MIME types

The following types are generally readable in most email clients:

* `text/plain`
* `text/html`
* `text/richtext`
* `text/css`

<Info>
  When multiple parts are present, the rendered body orders them as `text/plain`, then `text/html`, then any other types.
</Info>

### 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`

<Note>
  Other MIME types may be blocked from time to time when our abuse-prevention systems detect ongoing abuse involving
  that type.
</Note>
