Email
Custom adapter
Send email through any other provider with an adapter of your own.
An adapter is an object with one send function. It gets the full message and MUST throw when delivery fails. This one sends through an HTTP API:
tenon.config.ts
import { defineCms, type EmailAdapter } from "tenoncms";
const mailApi: EmailAdapter = {
async send(message) {
const response = await fetch("https://mail.example.com/send", {
method: "POST",
headers: {
"content-type": "application/json",
authorization: `Bearer ${process.env.MAIL_API_KEY}`,
},
body: JSON.stringify(message),
});
if (!response.ok) throw new Error(`Email delivery failed: ${response.status}`);
},
};
export default defineCms({
// ...
email: { adapter: mailApi, from: "My Site <hello@example.com>" },
});
message has from, to, subject, replyTo, text and html. Map them to the fields your provider expects.
Related resources
- Email: send your own mail and change the built-in emails.