Chat SDK

Chat SDK Proactive Outreach

Start new email conversations proactively by sending a fresh email with the MailBlastr SDK — replies flow back through your inbound webhook.

Conversational email does not have to start with an inbound message. To reach out first, just send a new email with the `mailblastr` SDK — no In-Reply-To header, since this message begins a new thread. When the recipient replies, the response arrives through your normal inbound webhook and you thread it with In-Reply-To/References.

Sending a proactive email

A proactive message is a plain send. Capture the returned Message-ID so you can match the recipient's reply back to this conversation.

import { MailBlastr } from 'mailblastr';

const mb = new MailBlastr(process.env.MAILBLASTR_API_KEY!);

async function openConversation(to: string, subject: string, text: string) {
  const { data, error } = await mb.emails.send({
    from: 'My Bot <bot@yourdomain.com>',
    to: [to],
    subject,
    text,
  });
  if (error) throw new Error(`${error.name}: ${error.message}`);
  return data; // store data.id to correlate the eventual reply
}

You can also send card emails in proactive threads — render a card to HTML and pass it as html, exactly as in Card emails.

Triggering via HTTP

A common pattern is exposing an HTTP endpoint that triggers outbound emails. This lets external systems — cron jobs, webhooks from other services, admin dashboards — send email through your bot.

async function handleNotify(req, res) {
  const { to, subject, message } = JSON.parse(await readBody(req));

  const email = await openConversation(to, subject ?? 'A message for you', message);

  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ ok: true, id: email.id }));
}

Then call it:

curl -X POST http://localhost:3000/notify \
  -H "Content-Type: application/json" \
  -d '{"to": "user@example.com", "subject": "Shipping update", "message": "Your order has shipped!"}'

When to use this

  • Welcome emails when a user signs up.
  • Order confirmations and shipping updates.
  • Alert notifications (monitoring, billing, security).
  • Scheduled digests or reminders.
When the recipient replies, the response arrives through your inbound email.received webhook (see Chat SDK). Match it back to this conversation by the In-Reply-To/References headers, which point at the Message-ID of the email you sent.