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 and send the link to someone on your team.

  1. Find the mailbox

    import { Platic } from "platic-sdk";
    
    const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! });
    
    const channels = await platic.channels.list();

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

  2. Write an email

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

    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
    });

    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.

  3. Reply in the same thread

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

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

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

    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. The HTML body is in the V1 read: get a conversation (V1).

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.

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.

Replying with send message

POST /v1/messages also replies to a thread, with text only. To start a thread, for HTML, or for attachments, use POST /v1/messages/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.