# Send an Email message

By following these instructions, you'll be able to setup an Email channel and use it to send messages through the API.

## Step 1: Setup your API Key

In order to send messages through the API, you'll need an API key. Click the bottom left menu and then select **User Settings**.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2Fus1tVPwCLRpM8lfjFBqO%2Fimage.png?alt=media&#x26;token=4b996d1f-57ec-4002-ad53-4ec76d7261bb" alt="" width="351"><figcaption><p>User Settings menu</p></figcaption></figure>

Head to **Security** -> **Access Keys** -> **Add new access key**.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2Fb5zVQk6yuLyYiQ326ERg%2Fimage.png?alt=media&#x26;token=8e8fc63f-9dfa-40fa-9405-d2030511e8c2" alt=""><figcaption><p>Access key management</p></figcaption></figure>

Create an access key with the role **Application Developer**.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2FlHchy4S6X2NZUjuTYTl3%2Fimage.png?alt=media&#x26;token=d32bc8ff-4637-4e78-8d5a-444999accc2c" alt="" width="375"><figcaption><p>Creating a new access key</p></figcaption></figure>

Now you have an access key you'll be able to use when sending messages through the API.

## Step 2: Create an email channel

In the top left menu, select **Manage Channels -> Email**.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2F3KHAkpxdqP9VOQ6aTe4Y%2Fimage.png?alt=media&#x26;token=504dec95-45c3-4835-be32-7d41ed4b8314" alt=""><figcaption><p>Channels management</p></figcaption></figure>

Click **Install Email** and fill out the information about your email channel.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2FztMimTljqjZiARyIOEVt%2Fimage.png?alt=media&#x26;token=b6bcda5d-c40c-445f-8a10-5abf365b8b3c" alt=""><figcaption><p>Email channel installation</p></figcaption></figure>

After creating your channel, you'll be presented with a few DNS records that need to be registered with your DNS provider. Once the DNS records are in place, click **Verify domain** at the bottom. You may need to retry this a few times due to DNS propagation times. If you're having difficulty with this step, check out the [Troubleshooting](#troubleshooting) section.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2FfsFRDv6JaulEhsSALGr3%2Fimage.png?alt=media&#x26;token=711ec08c-8e8c-405b-bd8a-2d40863d7611" alt="" width="563"><figcaption><p>Email DNS records</p></figcaption></figure>

If everything worked, in the **Health** tab you should see a message saying your channel is healthy and ready to be used.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2FKlL2XNVSEhBxovnjr748%2Fimage.png?alt=media&#x26;token=f2cbcdef-ba56-4498-bb12-1de2021ef83c" alt="" width="375"><figcaption><p>Health tab</p></figcaption></figure>

Lastly, take note of your channel ID in the settings tab, you'll need it when performing the API request.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2FOeYx0NWmqumTqmFxYGS8%2Fimage.png?alt=media&#x26;token=7cf7e92d-b550-434c-93cc-bf8a55452dc3" alt="" width="375"><figcaption><p>Channel ID</p></figcaption></figure>

## Step 3: Check your workspace ID

The last thing we need to send messages is to know your workspace ID. In the bottom left menu, select **User Settings** and navigate to **Organization** -> **Workspaces** and then select your workspace, now you should be able to take note of your workspace ID.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2FkrCZqnuOFj2ZvEi5INze%2Fimage.png?alt=media&#x26;token=f7d7cd74-12d2-40b2-8b94-eac0b33487b3" alt=""><figcaption><p>Workspace ID</p></figcaption></figure>

## Step 4: Send a message

Use the command below to perform a request that sends a message. You'll need to fill in your workspace ID, your channel ID, your API key, and your email.

{% tabs %}
{% tab title="Request" %}

```bash
curl -X POST 'https://api.bird.com/workspaces/<your workspace ID>/channels/<your channel ID>/messages' \
-H 'Authorization: AccessKey <your access key>' \
-H 'Content-Type: application/json' \
-d '{
  "receiver": {
    "contacts": [
      {
        "identifierValue": "<your email>"
      }
    ]
  },
  "body": {
    "type": "html",
    "html": {
      "metadata": {
        "subject": "Hello!"
      },
      "html": "<p>Congratulations, you just sent an email with Bird!</p>",
      "text": "Congratulations, you just sent an email with Bird!"
    }
  }
}'
```

{% endtab %}

{% tab title="Response (202 - Accepted)" %}

```json
{
  "id": "b0b858d3-75d7-4fe3-a5a3-8d7c8ee8471c",
  "channelId": "7b0eb8a0-606b-59f1-bd90-43cacb048146",
  "sender": {
    "connector": {
      "id": "fdd994a8-31fd-4b24-9c9c-0392f91aaf76",
      "identifierValue": "inbox@example.com"
    }
  },
  "receiver": {
    "contacts": [
      {
        "id": "18220490-9ef7-4a5a-9b9f-7db6903009d2",
        "identifierKey": "emailaddress",
        "identifierValue": "john.doe@bird.com",
        "platformAddress": "john.doe@bird.com"
      }
    ]
  },
  "body": {
    "type": "html",
    "html": {
      "text": "Congratulations, you just sent an email with Bird!",
      "html": "<p>Congratulations, you just sent an email with Bird!</p>",
      "metadata": {
        "subject": "Hello!"
      }
    }
  },
  "meta": {
    "email": {
      "subject": "Hello!"
    }
  },
  "reference": "",
  "parts": [],
  "status": "accepted",
  "reason": "",
  "direction": "outgoing",
  "context": {},
  "lastStatusAt": "2024-12-04T15:57:22.391Z",
  "createdAt": "2024-12-04T15:57:22.391Z",
  "updatedAt": "2024-12-04T15:57:22.391Z",
  "notification": {},
  "batchId": null
}
```

{% endtab %}
{% endtabs %}

## Step 5: Checking messages

You can verify the [message status](https://docs.bird.com/api/channels-api/message-status-and-interactions) in the following ways:

### 1. UI

In the developer console, you can access **Email** -> **Emails Log**.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2F22hMT4iNansxI1nxbs8d%2Fimage.png?alt=media&#x26;token=81ba1e70-d0f5-4fed-952c-ba6c6ce890de" alt=""><figcaption><p>Email logs</p></figcaption></figure>

Alternatively, you can navigate to your channel and switch to the **Logs** tab.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2F9HFh0Xa7C4gddpy50nSL%2Fimage.png?alt=media&#x26;token=a8b16fa3-d8d0-4f27-afd1-71131f8e99b3" alt=""><figcaption><p>Channel logs</p></figcaption></figure>

### 2. API

To retrieve message details through the API, refer to the [Messaging API Documentation](https://docs.bird.com/api/channels-api/api-reference/messaging#retrieving-messages). You can find more information on the available endpoints, request formats, and required parameters.

### 3. Webhook

In the Developer console, head to **Preferences** -> **Webhooks** and create a webhook subscription to the `channels` service with the event `email.outbound`. For additional information, refer to the [Notifications API](https://docs.bird.com/api/notifications-api).

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2F0xRaB6ZqkKJerpa62VNG%2Fimage.png?alt=media&#x26;token=1a811520-d83e-4de7-bb45-2b4b6c5a84e1" alt="" width="375"><figcaption><p>Creating webhook</p></figcaption></figure>

## Troubleshooting

### Unable to verify DNS records

If your DNS records can't be verified, use the `dig` tool to check that domains are responding with the expected value, for example:

```bash
$ dig scph1023._domainkey.bird.com txt +short @1.1.1.1
"v=DKIM1; k=rsa; h=sha256; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDM2lbd61qfnFm+EfN6nIRJYaDsBC25HF0tTw7im7qdCQ78CMRvVd9/dPmf6kPFkOQ7AHnji0uN26tpmeZ7e0B5ruPmomRAZhPMAo5okLM2ZyGfopy5JOIqwvE20NBC9S8PPIdp2Av5PvYy92ga+DY1HfWEyB6T2wbXuFyOKnuX/QIDAQAB"
```

Keep in mind it may take a few minutes for new DNS values to be propagated.

Another possibility is that your tracking domain is in use by another organization. To check if that's the case, make sure the health check for "Tracking Domain Exists" is OK.

<figure><img src="https://3210271997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdnJZeZvhOMhDQA8SpjQM%2Fuploads%2FEofHagOOUkKgJbwd6tVi%2FScreenshot%202024-12-04%20at%2012.53.32.png?alt=media&#x26;token=00edecdf-2aae-4b37-a01e-7c6004bc84f8" alt="" width="375"><figcaption><p>Tracking domain health check</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bird.com/api/quickstarts/send-an-email-message.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
