Reply to received emails
Reply in-thread by setting In-Reply-To (and References) to the received message_id when sending via POST /emails.
Email clients thread messages using the Message-ID header. To reply to a received email so it lands in the same conversation, send a new email via POST /emails with an In-Reply-To header set to the original message's message_id. Start the subject with Re: so clients group the replies together.
Get the message ID
The message_id is included in the email.received webhook payload:
{
"type": "email.received",
"data": {
"email_id": "56761188-7520-42d8-8898-ff6fc54ce618",
"message_id": "<111-222-333@email.example.com>",
"subject": "Sending this example",
"from": "Acme <onboarding@mailblastr.dev>",
"to": ["delivered@mailblastr.dev"]
}
}Use event.data.message_id as the In-Reply-To header value when sending your reply.
Send a reply in thread
Set the In-Reply-To header to the received message_id and prefix the subject with Re:. See Custom headers for how MailBlastr writes custom MIME headers.
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr('mb_xxxxxxxxx');
const { data, error } = await mb.emails.send({
"from": "Acme <hello@yourdomain.com>",
"to": ["delivered@example.com"],
"subject": "Re: Sending this example",
"html": "<p>Thanks for your email!</p>",
"headers": {
"In-Reply-To": "<111-222-333@email.example.com>"
}
});
console.log({ data, error });Reply headers
In-Reply-TostringrequiredThe message_id of the message you are replying to (e.g. <111-222-333@email.example.com>).
ReferencesstringoptionalSpace-separated list of every prior message_id in the thread, ending with the one you are replying to. Used for deep threading across multiple replies.
Replying multiple times in a thread
When you reply more than once in the same conversation, also set the References header to all previous message_ids separated by spaces, ending with the current one. This helps clients keep the thread structure correct.
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr('mb_xxxxxxxxx');
const { data, error } = await mb.emails.send({
"from": "Acme <hello@yourdomain.com>",
"to": ["delivered@example.com"],
"subject": "Re: Sending this example",
"html": "<p>Thanks for your email!</p>",
"headers": {
"In-Reply-To": "<111-222-333@email.example.com>",
"References": "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>"
}
});
console.log({ data, error });from must be on a verified sending domain. The reply is an ordinary outbound send via POST /emails; the In-Reply-To / References headers are what place it in the existing thread.