SDK
Messages
Send email and SMS messages through the SDK.
Send an email
const message = await connect.message.send({
channelType: "email",
emailDomainId: "dom_...",
to: "user@example.com",
subject: "Order confirmed",
body: "<h1>Thanks for your order!</h1><p>We'll ship it today.</p>",
});You can optionally set a from address. It must match the verified domain:
await connect.message.send({
channelType: "email",
emailDomainId: "dom_...",
to: "user@example.com",
from: "support@yourdomain.com",
subject: "Re: Your ticket",
body: "<p>We're looking into it.</p>",
});Send an SMS
const sms = await connect.message.send({
channelType: "sms",
phoneNumberId: "pn_...",
to: "+15559876543",
body: "Your verification code is 482910",
});Send with a template
If you've created a template, pass templateId and the message body will be rendered from the template with variable substitution:
await connect.message.send({
channelType: "email",
emailDomainId: "dom_...",
to: "user@example.com",
subject: "Welcome!",
body: "<p>Fallback if template fails</p>",
templateId: "tpl_...",
});Send to a contact
Pass contactId to associate the message with a contact:
await connect.message.send({
channelType: "email",
emailDomainId: "dom_...",
to: "user@example.com",
subject: "Hello",
body: "<p>Hi there</p>",
contactId: "ct_...",
});List messages
const { items } = await connect.message.list({
limit: 20,
offset: 0,
});Filter by status, channel, or direction:
const failed = await connect.message.list({
status: "failed",
channelType: "email",
direction: "outbound",
limit: 50,
offset: 0,
});Get a message
const message = await connect.message.get({ id: "msg_..." });Returns the message with its related domain, phone number, and template information.
Message statuses
| Status | Meaning |
|---|---|
queued | Created, waiting to be sent |
sent | Handed off to the delivery provider |
delivered | Confirmed delivered to the recipient |
failed | Delivery attempt failed |
bounced | Recipient address bounced |
rejected | Rejected by the provider |