Skip to content

API reference

email.send(options) configures outbound email. email.receive(options) configures inbound email.

Terminal window
import { email } from "@layeron/modules"

Options accepted by email.send(options) and email.receive(options).

FieldTypeDescription
namestringStable Email instance name.
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
domainstringCloudflare Email domain hostname. Layeron configures the requested Email capability for the connected Cloudflare zone during deploy.

Options accepted by email.send(options).

FieldTypeDescription
emailstring | undefinedDefault sender for mail.send(input). Use a local part such as noreply or a full address on the configured domain.
queueEmailSendQueueOptions | undefinedQueue controls for the internal Job that delivers outbound email.

Queue controls for outbound Email delivery.

FieldTypeDescription
consumerEmailSendQueueConsumerOptions | undefinedConsumer controls for the internal send Job queue.

Consumer controls for outbound Email delivery.

FieldTypeDescription
concurrencyint32 | undefinedMaximum concurrent send Job deliveries for this Email send instance. Defaults to 1.

Normalized Email module configuration.

FieldTypeDescription
kind”email”Module configuration discriminator for Email.
namestringStable Email instance name.
namespacestringPlatform namespace for the Email instance.
domainstringCloudflare Email domain hostname configured for this Email instance.
sendEmailSendConfig | undefinedOutbound Email Sending configuration when email.send(options) is declared.
receiveEmailReceiveConfig | undefinedInbound Email Routing configuration when email.receive(options) is declared.
templatesEmailTemplateConfig[] | undefinedCompiled templates registered on this Email instance.

Outbound email settings enabled when email.send(options) is declared.

FieldTypeDescription
enabledbooleanWhether this Email instance configures outbound Email Sending.
emailstring | undefinedDefault sender address normalized from email.send(options).email when configured.
bindingNamestring | undefinedCloudflare send_email binding used by the Job delivery Worker. Layeron sets this during compile.
queueEmailSendQueueConfig | undefinedQueue controls applied to the internal Job that delivers outbound email.

Normalized outbound Email queue configuration.

FieldTypeDescription
consumerEmailSendQueueConsumerConfigConsumer controls for the internal send Job queue.

Normalized outbound Email queue consumer configuration.

FieldTypeDescription
concurrencyint32Maximum concurrent send Job deliveries for this Email send instance.

Inbound email settings enabled when email.receive(options) is declared.

FieldTypeDescription
enabledbooleanWhether inbound email for this domain is routed to the Email product Worker.

Compiled Email template registered with mail.template(name, options).

FieldTypeDescription
namestringTemplate 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.
subjectstring | undefinedRendered subject with payload placeholders.
textstring | undefinedRendered plain text body with payload placeholders.
htmlstring | undefinedRendered HTML body with payload placeholders.

Template content accepted by mail.template(name, options).

FieldTypeDescription
render”static” | “dynamic” | undefinedTemplate render mode. Use static for payload-free React Email and dynamic for payload-driven React Email.
subjectunknown | undefinedSubject template. TypeScript accepts a string or a payload function.
textunknown | undefinedPlain text body template. TypeScript accepts a string or a payload function.
htmlunknown | undefinedHTML body template. TypeScript accepts a string or a payload function.
reactunknown | undefinedReact Email component rendered into HTML. static templates render once, dynamic templates render at send time.
componentunknown | undefinedAlias for react.

Email message delivered to the email.receive handler.

FieldTypeDescription
idstringMessage id from the email headers or a generated local id.
fromstringSender email address.
tostringRecipient email address.
ccstring[]Cc recipient addresses.
bccstring[]Bcc recipient addresses.
replyTostring | undefinedReply-To header value when present.
subjectstring | undefinedSubject header value when present.
textstring | undefinedPlain text body when present.
htmlstring | undefinedHTML body when present.
headersRecord<string>Normalized email headers keyed by lowercase header name.
rawstringRaw email source.
receivedAtstringISO timestamp when Layeron received the message.

Result returned after an inbound email handler runs.

FieldTypeDescription
status”processed” | “ignored”processed when a handler ran, ignored when no receive handler matched.
messageIdstringInbound message id.

Email message accepted by mail.send(input).

FieldTypeDescription
fromstring | undefinedSender 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.
tostring | string[]Recipient email address or addresses.
ccstring | string[] | undefinedCc recipient address or addresses.
bccstring | string[] | undefinedBcc recipient address or addresses.
replyTostring | undefinedReply-To email address.
subjectstring | undefinedEmail subject. Required when no template supplies a subject.
textstring | undefinedPlain text body.
htmlstring | undefinedHTML body.
templatestring | undefinedTemplate name registered with mail.template(name, options).
payloadRecord<unknown> | undefinedTemplate payload used to replace template placeholders.
dataRecord<unknown> | undefinedTemplate data used to replace template placeholders. Alias for payload.
headersRecord<string> | undefinedAdditional email headers.
metadataRecord<unknown> | undefinedApplication metadata stored with local outbox records and passed through product RPC.
tagsRecord<unknown> | undefinedApplication tags stored with local outbox records and passed through product RPC.
idempotencyKeystring | undefinedApplication idempotency key passed through product RPC.

Result returned after Layeron accepts an outbound email for Job-backed delivery.

FieldTypeDescription
status”queued” | “sending” | “sent” | “retry_scheduled” | “failed” | “unknown”Current send status. queued means the send run is durably recorded and ready for delivery.
messageIdstringOutbound email message id.
jobRunIdstring | undefinedJob run id that owns delivery, retry, and failure state.

Layeron Email module returned by email.send(options) or email.receive(options).

FieldTypeDescription
name”email”Module name.
configEmailModuleConfigNormalized Email module configuration.

Create a send-only Layeron Email module and configure Cloudflare Email Sending during deploy.

Terminal window
emailSend(options: EmailSendModuleOptions): EmailModule

Create a receive-only Layeron Email module and configure Cloudflare Email Routing during deploy.

Terminal window
emailReceive(options: EmailModuleOptions): EmailModule

Send one outbound email through a Layeron Email send module.

Terminal window
emailSendMessage(input: EmailSendInput): EmailSendMessageResult

Register an Email template and compile it into a Layeron Email template resource.

Terminal window
emailTemplate(name: string, options: EmailTemplateOptions): string