Skip to main content

@rtorcato/cf-common

Functions​

sendEmail()​

sendEmail(binding, message): Promise<EmailSendResult>

Defined in: index.ts:23

Send an email through a send_email binding. Pass the message as fields (from, to, subject, text/html, attachments, …) and the runtime builds the MIME for you, or pass an EmailMessage from cloudflare:email when you already have raw MIME.

A failed send (unverified sender or destination, a recipient the binding's allow list rejects, a quota or upstream error) throws a non-exposed 502 with code EMAIL_SEND_FAILED and the original error as cause. The detail names addresses, so it stays in logs and out of the response.

Example​

const mailer = getBinding<SendEmail>(env, 'EMAIL')
const { messageId } = await sendEmail(mailer, {
from: { name: 'App', email: 'noreply@example.com' },
to: 'user@example.com',
subject: 'Welcome',
text: 'Thanks for signing up.',
})

Parameters​

binding​

SendEmail

message​

EmailMessageBuilder | EmailMessage

Returns​

Promise<EmailSendResult>