Send Email
await ctx.email.send({
to: 'ada@example.com',
subject: 'Your invoice',
text: 'Your invoice is attached.',
html: '<p>Your invoice is attached.</p>',
});Outside a handler: import { email } from '@webstir-io/webstir-backend/email'. Sending from a queued job keeps a slow mail server out of the request and retries a failure.
Where it goes
EMAIL_URLis an SMTP URL:smtp://user:password@host:587, orsmtps://on port 465. Amazon SES, Postmark, Resend, Mailgun and any mail server offer SMTP.EMAIL_FROMis who it comes from, such asApp <hello@example.com>. Production requires it.- In development, with no
EMAIL_URL, email is printed in the terminal and kept in.webstir/email.log, one JSON line each. Nothing is sent. - In production, with no
EMAIL_URL, sending fails with an error instead of dropping the message.
A provider with its own API
Set a transport in src/backend/index.ts, before the server starts:
import { setEmailTransport } from '@webstir-io/webstir-backend/email';
setEmailTransport(async (message) => {
await fetch('https://api.example.com/send', { method: 'POST', body: JSON.stringify(message) });
});