Email via Resend (mail-resend)
Delivers the emails your app sends (password resets, notifications) through the Resend HTTP API. No SDK: one fetch call.
npx calm add mail-resend| Adds | |
|---|---|
| Files | app/blocks/mail-resend/index.js |
| Environment | RESEND_API_KEY=, MAIL_FROM=My App <no-reply@example.com> |
Set RESEND_API_KEY and MAIL_FROM, a sender on a domain you verified in Resend. MAIL_FROM takes precedence over mail.from in calm.config.js.
In development without a key, the block stays inactive and emails keep going to the devtools Mail panel. In production without a key, calm doctor reports an error.
Sending email#
Everything goes through app.mailer, so your code does not depend on the provider:
await ctx.app.mailer.send({
to: 'ada@example.com',
subject: 'Your invoice',
text: 'Thanks for your order.',
html: '<p>Thanks for your order.</p>',
});to can be one address or an array. A failed delivery throws with Resend's status and message. For retries, send from a job.
Without a mail block#
The built-in transport only works in development: it prints a short notice and hands the message to devtools. In production with no transport, emails are not sent and an error is logged, and calm doctor --prod warns about it. You can also register your own transport in a plugin:
calm.mailer.use({
name: 'my-provider',
async send({ to, from, subject, text, html }) { /* deliver it */ },
});Official documentation#
Read these before changing the block; they are also in app/blocks/mail-resend/AGENTS.md and in the devtools Blocks panel.
- Resend: Introduction
- Resend API: Send email
- Resend API reference (authentication, rate limits)
- Resend: Domains
For AI agents#
Coding agents read these notes in app/blocks/mail-resend/AGENTS.md:
- Read first:
app/blocks/mail-resend/index.js(onecalm.mailer.usetransport, about 30 lines). - Configuration: env
RESEND_API_KEY(secret) andMAIL_FROM. Nocalm.config.jsoptions. Without the key the block registers nothing: development mail stays in the devtools Mail panel andcalm doctorreports an error in production. - Send mail with
app.mailer.send({ to, subject, text, html })(calm.mailerinside blocks). Never call the Resend API directly from features, so tests and devtools keep seeing every message. - Invariant: never log or echo
RESEND_API_KEY. Errors contain only the HTTP status and the first 300 characters of Resend's answer. MAIL_FROMoverrides the per messagefromand must be an address on a domain verified in Resend, otherwise Resend refuses the request.- The transport forwards only
from,to,subject,textandhtml. To supportreply_to,cc,bcc,attachments,headersortags, map them insend()using Resend's field names.metais stripped by the core before the transport sees it. - Only one mail transport is active:
calm.mailer.usereplaces the previous one, so do not install mail-smtp next to it. - Pitfall: Resend rate limits API requests (429). Send bulk mail from a job (jobs block) with retries, not in a loop inside a request.
- Pitfall:
send()throws on any non 2xx answer. The notifications block catches it; your own callers should too, or send from a job.