Skip to main content
The @talosjs/mailer component sends transactional emails. The mailer renders a React node to HTML on the server, so your email bodies are plain components rather than strings you concatenate by hand. Every sender implements the same IMailer interface, which is just a single send method, so callers stay identical no matter how the mail is delivered. MailerLayout provides a styled header/body/footer shell to build templates on.

What the mailer gives you

Every mailer implements IMailer (send) and is registered with a decorator, so you resolve and inject it like any other service. Email bodies are React nodes, rendered to HTML with renderToString, which means you compose them the way you compose UI. The MailerLayout component ships with Header, Body, and Footer subcomponents and email-safe defaults. Credentials and the default sender come from environment variables, and any send can override them. The packaged ResendMailer delivers through the Resend API.

How it works

You resolve a mailer from the container and call send. The mailer renders the content React node to HTML, resolves the sender (from the call or the environment), and delivers the message. The config object passed to send: The sender is resolved per call: config.from wins, otherwise MAILER_SENDER_NAME and MAILER_SENDER_ADDRESS are used. If neither yields a name and address, send throws. Each entry in attachments is a MailerAttachmentType:

Environment variables

Decorator and usage

@decorator.mailer()

Registers a mailer class with the container. It accepts an optional scope (defaults to singleton). ResendMailer is already decorated; use the decorator on your own mailer classes so they can be resolved and injected. Resolve the mailer from the container and send an email. The body is just a React node:
Override the sender per call when a message should come from a specific address:
A typical mailer wraps a template and delegates to the injected ResendMailer. Register it with the decorator and inject the packaged sender directly:

Exceptions

The component throws MailerException when it is misconfigured or a send cannot complete. It carries a machine-readable key, a human-readable message, and a data object.

Working with mailers

Configure MAILER_SENDER_NAME and MAILER_SENDER_ADDRESS once so every send has a fallback, then override from only when a message needs a different address. Compose bodies on MailerLayout (Header, Body, Footer) for email-safe markup instead of raw HTML strings, and keep your templates as props-driven functions: pass data in, return a React node, and they render in tests without sending anything. It helps to wrap a template per email type. A dedicated mailer like WelcomeMailer, delegating to the injected ResendMailer, keeps its subject, template, and props in one place. Catch MailerException at send sites and read error.key to tell a configuration problem apart from a delivery one, and never leak credentials in the process. Always resolve mailers through the container rather than constructing them, so credentials and defaults stay wired consistently.

CLI command

Scaffold a mailer, its JSX template, and their tests with the generator. It writes the class under modules/<module>/src/mailers/<Name>Mailer.ts, the template alongside it, and installs @talosjs/mailer if it is missing.
The generated mailer wraps its template and delegates to the injected IMailer, ready for you to refine the subject and props.
The companion template is a props-driven function built on MailerLayout:
See mailer:create for the full command reference.

Use with Claude and Codex

The generator ships a matching mailer:create skill. It runs the scaffold, then guides your AI agent through completing the mailer: refining the send config, filling in the template props, and wiring up its tests. Initialize the skills once for your agent.
Then ask Claude in natural language. It maps the request to the generator, runs it, and fills in the implementation:
Prompt
For example, the prompt above maps to mailer:create --name=Welcome, then builds the welcome template and completes the send method.