---
docId: doc_d8e20a47ad804afb945b36bfba18dbda
title: Email through the API
description: "Send and reply to emails from a connected mailbox and read its threads."
---

<script>
  import { Note, Steps, Ways } from '$lib/components';
</script>

# Email through the API

Send and reply to emails from your connected mailbox. Read the thread as a conversation.

**Before you start:** a Gmail, Outlook, or your-own-domain mailbox connected in Platica, under Integrations. Mailboxes are finished there, in their wizard; through the API you can [request the connection](/api-reference/channels/connections/create) and send the link to someone on your team.

<Steps>
<Steps.Step>

**Find the mailbox**

<Ways>
<Ways.Way name="asistente">
<Ways.Say>

Which email mailboxes do I have connected?

</Ways.Say>

Your assistant uses `list_channels`.

</Ways.Way>
<Ways.Way name="api">

```bash
curl https://api.platic.ai/v1/channels \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
import { Platic } from "platic-sdk";

const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! });

const channels = await platic.channels.list();
```

</Ways.Way>
</Ways>

Each mailbox is a channel with `platform: "email"` and an `id` with the `em-` prefix: save it in `CHANNEL_ID`.

</Steps.Step>
<Steps.Step>

**Write an email**

Without a conversation, the email starts a new thread. If you send an agent, it answers when Ana replies.

<Ways>
<Ways.Way name="asistente">
<Ways.Say>

Send an email to ana@example.com from sales@ with the subject "Your quote" and have the Sales agent handle her reply.

</Ways.Say>

Your assistant uses `send_email`.

</Ways.Way>
<Ways.Way name="api">

```bash
curl https://api.platic.ai/v1/messages/email \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "channelId": "'$CHANNEL_ID'",
    "to": "ana@example.com",
    "subject": "Your quote",
    "text": "Hi Ana, here is your quote.",
    "agentId": "'$AGENT_ID'"
  }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
const channelId = process.env.CHANNEL_ID!;

const sent = await platic.messages.sendEmail({
  channelId,
  to: "ana@example.com",
  subject: "Your quote",
  text: "Hi Ana, here is your quote.",
  agentId: process.env.AGENT_ID
});
```

</Ways.Way>
</Ways>

Save `data.conversationId` in `CONVERSATION_ID` to continue the same thread. If Ana does not exist as a contact, she is created. To send HTML or attachments, see [send an email](/api-reference/messages/send-email).

</Steps.Step>
<Steps.Step>

**Reply in the same thread**

With the conversation, the email goes out as a reply, with the same subject.

<Ways>
<Ways.Way name="asistente">
<Ways.Say>

Reply to Ana that I will send it as a PDF.

</Ways.Say>

Your assistant uses `send_email`.

</Ways.Way>
<Ways.Way name="api">

```bash
curl https://api.platic.ai/v1/messages/email \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "channelId": "'$CHANNEL_ID'",
    "conversationId": "'$CONVERSATION_ID'",
    "text": "Sure, I will send it as a PDF."
  }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
await platic.messages.sendEmail({
  channelId,
  conversationId: sent.conversationId,
  text: "Sure, I will send it as a PDF."
});
```

</Ways.Way>
</Ways>

</Steps.Step>
<Steps.Step>

**Read the thread**

<Ways>
<Ways.Way name="asistente">
<Ways.Say>

What did Ana reply?

</Ways.Say>

Your assistant uses `list_conversation_messages_v2`.

</Ways.Way>
<Ways.Way name="api">

```bash
curl "https://api.platic.ai/v2/conversations/$CONVERSATION_ID/messages?fields=createdAt,sender,content,email" \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
const thread = await platic.conversations.messages.list(sent.conversationId, {
  fields: ["createdAt", "sender", "content", "email"],
});
```

</Ways.Way>
</Ways>

Each message has `content` in plain text and, when you ask for it in `fields`, an `email` block with the subject, who sent it, the recipients and the attachments. The conversation has its own `email`, with the subject and the mailbox. See [the conversation's messages](/api-reference/conversations/messages). The HTML body is in the V1 read: [get a conversation (V1)](/api-reference/conversations/v1/get#the-email-block).

</Steps.Step>
</Steps>

Your team sees the same threads in Platica's inbox.

## Each thread is a conversation

When you connect a mailbox, each email thread is a conversation, with its contact and its agent. A contact can have several threads in the same mailbox: one per subject.

- To list only email, use `platform=email` in [list conversations](/api-reference/conversations/list).
- To find a contact by their email, use [get a contact](/api-reference/contacts/get) with the email instead of the id.

## New emails by webhook

Emails that arrive and emails that go out trigger `message.created`, like any other message. `data.message.email` has the email block and `data.conversation.email` the thread's. See [payloads](/api-reference/webhooks/payloads#messages).

## Replying with send message

[`POST /v1/messages`](/api-reference/messages/send#email) also replies to a thread, with text only. To start a thread, for HTML, or for attachments, use [`POST /v1/messages/email`](/api-reference/messages/send-email).

## Limits

- No copy (`cc`) or blind copy (`bcc`).
- Up to 10 attachments per email. For now, each attachment's URL has to be a file stored in Platica.
- No email campaigns.
- An agent answers emails, but does not start threads on its own.
- Mailboxes on your own domain write and reply the same as Gmail and Outlook. They are connected in Platica, under [Email](/help/integrations/email).

<Note type="important">

[Connecting a channel](/api-reference/channels/connections/create) with `type` `gmail`, `outlook`, or `email` creates a pending connection: `authorizeIn` opens the mailbox wizard in Platica, and the connection becomes `connected` when someone on your team finishes it. That connection has no shareable link (`shareUrl`).

</Note>
