Get started
This guide adds outbound and inbound email to a Layeron backend.
Add Email
Section titled “Add Email”Create one instance for sending and another for receiving.
import { backend } from "@layeron/core"import { email } from "@layeron/modules"
const app = backend({ project: "demo",})
const outbound = email.send({ name: "transactional", namespace: "comms", domain: "mail.example.com", email: "hello",})
const inbound = email.receive({ name: "support", namespace: "comms", domain: "support.example.com",}, async (message) => { console.log(message.from, message.to, message.subject)})
app.use(outbound)app.use(inbound)Each Email instance uses the domain as its Cloudflare email identity. The domain must belong to a Cloudflare zone in the connected account.
Send a welcome email
Section titled “Send a welcome email”Register a template and send through the outbound instance.
const welcome = outbound.template<{ name: string }>("welcome", { subject: ({ name }) => `Welcome ${name}`, text: ({ name }) => `Hello ${name}. Welcome to our app.`,})
app.post("/welcome", async () => { return await outbound.send({ to: "ada@example.com", template: welcome, payload: { name: "Ada" }, })})Deploy
Section titled “Deploy”layeron deployNext Steps
Section titled “Next Steps”- Send email: Configure outbound delivery, idempotency, metadata, headers, deployment, and local dev.
- Receive email: Configure inbound routing, handlers, message fields, deploy behavior, and local tests.
- Templates: Register string templates or React Email templates and render them at send time.
- API reference: Review Email options, configs, message shapes, and module operations.