API reference
email.send(options) configures outbound email. email.receive(options) configures inbound email.
Import
Section titled “Import”import { email } from "@layeron/modules"EmailModuleOptions
Section titled “EmailModuleOptions”Options accepted by email.send(options) and email.receive(options).
| Field | Type | Description |
|---|---|---|
name | string | Stable Email instance name. |
namespace | string | undefined | Platform namespace for the instance. Defaults to default. |
domain | string | Cloudflare Email domain hostname. Layeron configures the requested Email capability for the connected Cloudflare zone during deploy. |
EmailSendModuleOptions
Section titled “EmailSendModuleOptions”Options accepted by email.send(options).
| Field | Type | Description |
|---|---|---|
email | string | undefined | Default sender for mail.send(input). Use a local part such as noreply or a full address on the configured domain. |
queue | EmailSendQueueOptions | undefined | Queue controls for the internal Job that delivers outbound email. |
EmailSendQueueOptions
Section titled “EmailSendQueueOptions”Queue controls for outbound Email delivery.
| Field | Type | Description |
|---|---|---|
consumer | EmailSendQueueConsumerOptions | undefined | Consumer controls for the internal send Job queue. |
EmailSendQueueConsumerOptions
Section titled “EmailSendQueueConsumerOptions”Consumer controls for outbound Email delivery.
| Field | Type | Description |
|---|---|---|
concurrency | int32 | undefined | Maximum concurrent send Job deliveries for this Email send instance. Defaults to 1. |
EmailModuleConfig
Section titled “EmailModuleConfig”Normalized Email module configuration.
| Field | Type | Description |
|---|---|---|
kind | ”email” | Module configuration discriminator for Email. |
name | string | Stable Email instance name. |
namespace | string | Platform namespace for the Email instance. |
domain | string | Cloudflare Email domain hostname configured for this Email instance. |
send | EmailSendConfig | undefined | Outbound Email Sending configuration when email.send(options) is declared. |
receive | EmailReceiveConfig | undefined | Inbound Email Routing configuration when email.receive(options) is declared. |
templates | EmailTemplateConfig[] | undefined | Compiled templates registered on this Email instance. |
EmailSendConfig
Section titled “EmailSendConfig”Outbound email settings enabled when email.send(options) is declared.
| Field | Type | Description |
|---|---|---|
enabled | boolean | Whether this Email instance configures outbound Email Sending. |
email | string | undefined | Default sender address normalized from email.send(options).email when configured. |
bindingName | string | undefined | Cloudflare send_email binding used by the Job delivery Worker. Layeron sets this during compile. |
queue | EmailSendQueueConfig | undefined | Queue controls applied to the internal Job that delivers outbound email. |
EmailSendQueueConfig
Section titled “EmailSendQueueConfig”Normalized outbound Email queue configuration.
| Field | Type | Description |
|---|---|---|
consumer | EmailSendQueueConsumerConfig | Consumer controls for the internal send Job queue. |
EmailSendQueueConsumerConfig
Section titled “EmailSendQueueConsumerConfig”Normalized outbound Email queue consumer configuration.
| Field | Type | Description |
|---|---|---|
concurrency | int32 | Maximum concurrent send Job deliveries for this Email send instance. |
EmailReceiveConfig
Section titled “EmailReceiveConfig”Inbound email settings enabled when email.receive(options) is declared.
| Field | Type | Description |
|---|---|---|
enabled | boolean | Whether inbound email for this domain is routed to the Email product Worker. |
EmailTemplateConfig
Section titled “EmailTemplateConfig”Compiled Email template registered with mail.template(name, options).
| Field | Type | Description |
|---|---|---|
name | string | Template name referenced by the template field in mail.send(input). |
render | ”static” | “dynamic” | Template render mode. static renders React Email once, dynamic renders React Email with each send payload. |
subject | string | undefined | Rendered subject with payload placeholders. |
text | string | undefined | Rendered plain text body with payload placeholders. |
html | string | undefined | Rendered HTML body with payload placeholders. |
EmailTemplateOptions
Section titled “EmailTemplateOptions”Template content accepted by mail.template(name, options).
| Field | Type | Description |
|---|---|---|
render | ”static” | “dynamic” | undefined | Template render mode. Use static for payload-free React Email and dynamic for payload-driven React Email. |
subject | unknown | undefined | Subject template. TypeScript accepts a string or a payload function. |
text | unknown | undefined | Plain text body template. TypeScript accepts a string or a payload function. |
html | unknown | undefined | HTML body template. TypeScript accepts a string or a payload function. |
react | unknown | undefined | React Email component rendered into HTML. static templates render once, dynamic templates render at send time. |
component | unknown | undefined | Alias for react. |
EmailInboundMessage
Section titled “EmailInboundMessage”Email message delivered to the email.receive handler.
| Field | Type | Description |
|---|---|---|
id | string | Message id from the email headers or a generated local id. |
from | string | Sender email address. |
to | string | Recipient email address. |
cc | string[] | Cc recipient addresses. |
bcc | string[] | Bcc recipient addresses. |
replyTo | string | undefined | Reply-To header value when present. |
subject | string | undefined | Subject header value when present. |
text | string | undefined | Plain text body when present. |
html | string | undefined | HTML body when present. |
headers | Record<string> | Normalized email headers keyed by lowercase header name. |
raw | string | Raw email source. |
receivedAt | string | ISO timestamp when Layeron received the message. |
EmailReceiveResult
Section titled “EmailReceiveResult”Result returned after an inbound email handler runs.
| Field | Type | Description |
|---|---|---|
status | ”processed” | “ignored” | processed when a handler ran, ignored when no receive handler matched. |
messageId | string | Inbound message id. |
EmailSendInput
Section titled “EmailSendInput”Email message accepted by mail.send(input).
| Field | Type | Description |
|---|---|---|
from | string | undefined | Sender local part or full sender email address. The address domain must match the Email instance domain. Required when email.send(options).email is not configured. |
to | string | string[] | Recipient email address or addresses. |
cc | string | string[] | undefined | Cc recipient address or addresses. |
bcc | string | string[] | undefined | Bcc recipient address or addresses. |
replyTo | string | undefined | Reply-To email address. |
subject | string | undefined | Email subject. Required when no template supplies a subject. |
text | string | undefined | Plain text body. |
html | string | undefined | HTML body. |
template | string | undefined | Template name registered with mail.template(name, options). |
payload | Record<unknown> | undefined | Template payload used to replace template placeholders. |
data | Record<unknown> | undefined | Template data used to replace template placeholders. Alias for payload. |
headers | Record<string> | undefined | Additional email headers. |
metadata | Record<unknown> | undefined | Application metadata stored with local outbox records and passed through product RPC. |
tags | Record<unknown> | undefined | Application tags stored with local outbox records and passed through product RPC. |
idempotencyKey | string | undefined | Application idempotency key passed through product RPC. |
EmailSendMessageResult
Section titled “EmailSendMessageResult”Result returned after Layeron accepts an outbound email for Job-backed delivery.
| Field | Type | Description |
|---|---|---|
status | ”queued” | “sending” | “sent” | “retry_scheduled” | “failed” | “unknown” | Current send status. queued means the send run is durably recorded and ready for delivery. |
messageId | string | Outbound email message id. |
jobRunId | string | undefined | Job run id that owns delivery, retry, and failure state. |
EmailModule
Section titled “EmailModule”Layeron Email module returned by email.send(options) or email.receive(options).
| Field | Type | Description |
|---|---|---|
name | ”email” | Module name. |
config | EmailModuleConfig | Normalized Email module configuration. |
Operations
Section titled “Operations”emailSend
Section titled “emailSend”Create a send-only Layeron Email module and configure Cloudflare Email Sending during deploy.
emailSend(options: EmailSendModuleOptions): EmailModuleemailReceive
Section titled “emailReceive”Create a receive-only Layeron Email module and configure Cloudflare Email Routing during deploy.
emailReceive(options: EmailModuleOptions): EmailModuleemailSendMessage
Section titled “emailSendMessage”Send one outbound email through a Layeron Email send module.
emailSendMessage(input: EmailSendInput): EmailSendMessageResultemailTemplate
Section titled “emailTemplate”Register an Email template and compile it into a Layeron Email template resource.
emailTemplate(name: string, options: EmailTemplateOptions): string