Events and inboundView as Markdown

Replying to inbound mail

To answer an inbound message so it appears in the same conversation in Gmail, Outlook and Apple Mail, send a normal email with two extra headers:

  • In-Reply-To: the original message_id, in angle brackets.
  • References: the original references followed by its message_id, each in angle brackets and separated by spaces.

Also reply to the reply_to address when there is one, otherwise to from, and prefix the subject with Re:.

With the Node.js SDK

inbound.reply does all of this for you:

import { Voozin, verifyWebhook } from "voozin";
 
const voozin = new Voozin(process.env.VOOZIN_API_KEY);
 
export async function POST(request: Request) {
  const event = await verifyWebhook(await request.text(), request.headers, process.env.VOOZIN_WEBHOOK_SECRET!);
  if (event.type === "inbound.received") {
    await voozin.inbound.reply(event.data, {
      from: "Acme Support <support@acme.com>",
      text: "Thanks for your message. We'll get back to you within a day.",
    });
  }
  return new Response(null, { status: 204 });
}

Any other send option (html, cc, attachments, tags, metadata) can be passed as well. Pass { idempotencyKey: event.data.id } as the third argument so a webhook retry never sends the reply twice.

With the REST API

curl https://api.voozin.com/v1/emails \
  -H "Authorization: Bearer $VOOZIN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: reply-8a4f2c1e" \
  -d '{
    "from": "Acme Support <support@acme.com>",
    "to": ["ada@example.com"],
    "subject": "Re: Order #1042 hasn'\''t arrived",
    "text": "Thanks for your message. We'\''ll get back to you within a day.",
    "headers": {
      "In-Reply-To": "<CAF7x…@mail.gmail.com>",
      "References": "<CAF7x…@mail.gmail.com>"
    }
  }'

Reply addresses that route back to your app

Send from an address that matches an inbound route, for example support@acme.com, or a per-conversation address such as reply+ticket-123@acme.com with the route pattern reply+*. When the customer answers, the reply arrives as another inbound.received event, and you can find the conversation from the recipient address or from in_reply_to.

Tips

  • Never reply automatically to messages that look automated: skip events whose headers include Auto-Submitted (other than no), Precedence: bulk or List-Id, and empty mail_from (bounces). This prevents mail loops.
  • Quote the original text below your answer if your users expect it; it isn't added automatically.
  • The sending address must be on a verified domain.