Queue Email method 📧 Emails
Queues an email message for asynchronous processing and returns immediately with a request ID.
The email will be processed in the background, and you'll receive webhook events for all delivery status updates (e.g. dropped, processed, delivered, hard-bounced). These webhook events are identical to those sent for the synchronous /send endpoint.
Use this endpoint when you need to send emails without waiting for processing to complete. This can improve your application's response time, especially when sending to multiple recipients.
Usage
import { MailChannelsClient, Emails } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const emails = new Emails(mailchannels)
const { data, error } = await emails.queue({
from: 'from@example.com',
to: 'to@example.com',
subject: 'Your subject',
html: '<p>Your email content</p>',
text: 'Your email content',
})import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.emails.queue({
from: 'from@example.com',
to: 'to@example.com',
subject: 'Your subject',
html: '<p>Your email content</p>',
text: 'Your email content',
})Params
optionsEmailsSendOptionsrequired: Send optionsEmailsSendOptions.attachments(EmailsSendAttachment | Promise<EmailsSendAttachment>)[]optional: An array of attachments to be sent with the email.contentstringrequired: The attachment data, encoded in Base64.filenamestringrequired: The name of the attachment file.typestringoptional: The MIME type of the attachment.contentIdstringoptional: TheContent-IDheader value for inline attachments, referenced from HTML withcid:.disposition"attachment" | "inline"optional: TheContent-Dispositionheader value for the attachment. Defaults toattachment.
IMPORTANT
Usage notes:
- Multiple attachments can be included in a single email.
- Maximum of
1000attachments per email. - Combined size limit (attachments + email content) is
30MB. - Base64 encoding is required for all attachment content.
campaignIdstringoptional: The campaign identifier. If specified, this ID will be included in all relevant webhooks. It can be up to 48 UTF-8 characters long and must not contain spaces.bccEmailsSendRecipient[] | EmailsSendRecipient | string[] | stringoptional: The BCC recipients of the email.ccEmailsSendRecipient[] | EmailsSendRecipient | string[] | stringoptional: The CC recipients of the email.dkimobjectoptional: The DKIM settings for the email.domainstringrequired: The domain to sign the email with.privateKeystringoptional: The private key to sign the email with. Can be undefined if the domain has an active DKIM key.selectorstringrequired: The DKIM selector to use.
envelopeFromEmailsSendRecipient | stringoptional: Optional envelope sender address. If not set, the envelope sender defaults to thefrom.emailfield. Can be overridden per-personalization. Only the email portion is used; the name field is ignored.fromEmailsSendRecipient | stringrequired: The sender of the email.headersRecord<string, string>optional: An object containing key-value pairs, where both keys (header names) and values must be strings. These pairs represent custom headers to be substituted.IMPORTANT
Please note the following restrictions and behavior:
- Reserved headers: The following headers cannot be modified:
Authentication-Results,BCC,CC,Content-Transfer-Encoding,Content-Type,DKIM-Signature,From,Message-ID,Received,Reply-To,Subject,To. - Header precedence: If a header is defined in both the personalizations object and the root headers, the value from personalizations will be used.
- Case sensitivity: Headers are treated as case-insensitive. If multiple headers differ only by case, only one will be used, with no guarantee of which one.
- Reserved headers: The following headers cannot be modified:
toEmailsSendRecipient[] | EmailsSendRecipient | string[] | stringrequired: The recipients of the email.trackingEmailsSendTrackingoptional: Adjust open and click tracking for the message.clickobjectoptional: Click tracking settings.enablebooleanoptional: Enable click tracking.
openobjectoptional: Open tracking settings.enablebooleanoptional: Enable open tracking.
INFO
Tracking for your messages requires a subscription that supports open and click tracking.
Only links (
<a>tags) meeting all of the following conditions are processed for click tracking:- The URL is non-empty.
- The URL starts with
httporhttps. - The link does not have a
clicktrackingattribute set tooff.
replyToEmailsSendRecipient | stringoptional: The reply-to address of the email.subjectstringrequired: The subject of the email.htmlstringoptional: The HTML content of the email.textstringoptional: The plain text content of the email.TIP
Including a plain text version of your email ensures that all recipients can read your message, including those with email clients that lack HTML support.
You can use the
html-to-textpackage to convert your HTML content to plain text.contentEmailsSendContent[]optional: Send the body of your message in multiple different formats. The recipient's email client will render the message using the content type that best fits their environment.typestringrequired: The MIME type of the content you are including in your email.valuestringrequired: The actual content of the specified MIME type that you are including in the message.WARNING
Cannot contain a
text/htmlentry whenhtmlis set, or atext/plainentry whentextis set.
NOTE
For more information about sending emails with multiple content parts, see the MailChannels documentation.
IMPORTANT
Either
html,text, orcontentmust be provided.templateEmailsSendTemplateoptional: Template configuration for rendering email content with a template engine.typeEmailsSendTemplateTyperequired: The template type of the contentdataRecord<string, EmailsSendTemplateValue>optional: Template variables, overridable per-personalization. An object containing key-value pairs of variables to set for template rendering.
IMPORTANT
Keys must be strings, and values can be one of the following types:
- string
- number
- boolean
- list, whose values are all of permitted types
- map, whose keys must be strings, and whose values are all of permitted types
personalizationsEmailsSendPersonalization[]optional: Explicit personalization objects for advanced payloads with multiple recipient groups or per-personalization overrides.transactionalbooleanoptional: Mark these messages as transactional or non-transactional. In order for a message to be marked as non-transactional, it must have exactly one recipient per personalization, and it must be DKIM signed. 400 Bad Request will be returned if there are more than one recipient in any personalization for non-transactional messages. If a message is marked as non-transactional, it changes the sending process as follows: List-Unsubscribe headers will be added.
Response
dataobject | nullnullablequeuedAtstringguaranteed: ISO 8601 timestamp when the request was queued for processing.requestIdstringguaranteed: Unique identifier for tracking this async request. Will be included in all webhook events for this request.
errorErrorResponse | nullnullable: Error information if the operation failed.messagestringguaranteed: A human-readable description of the error.statusCodenumber | nullnullable: The HTTP status code from the API, ornullif the error is not related to an HTTP request. This field is intended for diagnostic use only and should not be relied upon.typestringguaranteed: A string identifier for the type of error. This field is intended for diagnostic use only and should not be relied upon.
Type declarations
Signature
async function queue (options: EmailsSendOptions): Promise<EmailsQueueResponse>Response type declarations
interface ErrorResponse {
message: string;
statusCode: number | null;
type: ErrorType;
}type DataResponse<T> = {
data: T;
error: null;
} | {
data: null;
error: ErrorResponse;
};Send type declarations
interface EmailsSendRecipient {
email: string;
name?: string;
}type EmailsSendRecipientInput = EmailsSendRecipient[] | EmailsSendRecipient | string[] | string;interface EmailsSendDkim {
domain?: string;
privateKey?: string;
selector?: string;
}interface EmailsSendPersonalization {
bcc?: EmailsSendRecipientInput;
cc?: EmailsSendRecipientInput;
dkim?: EmailsSendDkim;
envelopeFrom?: EmailsSendRecipient | string;
from?: EmailsSendRecipient | string;
headers?: Record<string, string>;
replyTo?: EmailsSendRecipient | string;
subject?: string;
to: EmailsSendRecipientInput;
template?: Required<Omit<EmailsSendTemplate, "type">>;
}interface EmailsSendAttachment {
content: string;
filename: string;
type?: string;
contentId?: string;
disposition?: "attachment" | "inline";
}interface EmailsSendTracking {
click?: {
enable?: boolean;
};
open?: {
enable?: boolean;
};
}interface EmailsSendOptionsBase {
attachments?: (EmailsSendAttachment | Promise<EmailsSendAttachment>)[];
campaignId?: string;
bcc?: EmailsSendRecipientInput;
cc?: EmailsSendRecipientInput;
dkim?: EmailsSendDkim;
envelopeFrom?: EmailsSendRecipient | string;
from: EmailsSendRecipient | string;
headers?: Record<string, string>;
personalizations?: EmailsSendPersonalization[];
to?: EmailsSendRecipientInput;
tracking?: EmailsSendTracking;
replyTo?: EmailsSendRecipient | string;
subject: string;
template?: EmailsSendTemplate;
transactional?: boolean;
}type EmailsSendTargetOptions =
| {
personalizations: (Omit<EmailsSendPersonalization, "template"> & { template?: never })[];
to?: never;
cc?: never;
bcc?: never;
}
| {
template: EmailsSendTemplate;
personalizations: EmailsSendPersonalization[];
to?: never;
cc?: never;
bcc?: never;
}
| {
personalizations?: never;
to: EmailsSendRecipientInput;
cc?: EmailsSendRecipientInput;
bcc?: EmailsSendRecipientInput;
};interface EmailsSendContent {
type: string;
value: string;
}type EmailsSendOptions = EmailsSendOptionsBase & EmailsSendTargetOptions & (
| {
html: string;
text?: string;
content?: EmailsSendContent[];
}
| {
html?: string;
text: string;
content?: EmailsSendContent[];
}
| {
html?: string;
text?: string;
content: EmailsSendContent[];
}
);type EmailsQueueResponse = DataResponse<{
queuedAt: string;
requestId: string;
}>;Source
Source • Playground • Docs • Tests