Skip to content

Get started

This guide adds outbound and inbound email to a Layeron backend.

Create one instance for sending and another for receiving.

Terminal window
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.

Register a template and send through the outbound instance.

Terminal window
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" },
})
})
Terminal window
layeron deploy
  • 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.