Email

env.EMAIL sends transactional email from your app, receipts, notifications, magic links, through a managed delivery service, and your app can receive email too. There are no SMTP credentials or API keys to set up.

Sending

env.EMAIL is switched on automatically the first time you deploy code that uses it. There is nothing to enable. Your assistant can also turn it on ahead of time (manage_resource with action: attach).
// api/notify.js
export default {
  async fetch(request, env, ctx) {
    await env.EMAIL.send({
      to: "customer@example.com",
      subject: "Your order shipped",
      html: "<h1>On its way!</h1><p>Tracking: ABC123</p>",
      text: "On its way! Tracking: ABC123",
    });
    return Response.json({ ok: true });
  },
};

Pass to, subject, and an html and/or text body. Optionally set from to choose a verified sender; otherwise the app's default sender is used. The platform handles the routing details for you.

Copies, replies and threads

Add cc and bcc (one address or a list; up to 50 recipients in all). send() returns the message's messageId: store it, and when you send a reply, pass it as In-Reply-To and References so Gmail and Outlook show the messages as one conversation. A reply that comes back to your app carries it too (message.inReplyTo in onEmail).

const first = await env.EMAIL.send({
  from: "Support <support@yourdomain.com>",
  to: "customer@example.com",
  cc: ["sales@yourdomain.com"],
  subject: "Your ticket #42",
  text: "We're on it.",
});
// later, a reply in the same thread:
await env.EMAIL.send({
  from: "Support <support@yourdomain.com>",
  to: "customer@example.com",
  subject: "Re: Your ticket #42",
  text: "Fixed!",
  headers: { "In-Reply-To": first.messageId, "References": first.messageId },
});

Allowed headers: In-Reply-To, References, List-Unsubscribe, List-Unsubscribe-Post, List-Id and X-Entity-Ref-ID.

Bounces and spam reports

Export onBounce from api/email.js and your app hears about every message it sent that bounced or that a recipient reported as spam, so you can stop emailing that address:

// api/email.js
export async function onBounce(event, env) {
  // event = { event: "bounce" | "complaint", messageId, bounceType, bounceSubType,
  //           complaintType, recipients: [{ address, status, diagnostic }], subject, at }
  if (event.event === "complaint" || event.bounceType === "Permanent") {
    for (const r of event.recipients) {
      await env.DB.prepare("UPDATE users SET email_ok = 0 WHERE email = ?").bind(r.address).run();
    }
  }
}

bounceType "Permanent" means the address doesn't exist; "Transient" is temporary (for example a full mailbox). Each workspace has its own sending reputation: if too many of a workspace's emails bounce or are reported as spam, sending pauses for that workspace only (other workspaces are unaffected) and send() says so. Contact support to review and resume.

Attachments

Attach files by passing an attachments array, each item is a filename plus base64-encoded content (and an optional contentType). Handy for receipts, invoices, exports, or an iCal invite generated by your app:

await env.EMAIL.send({
  to: "customer@example.com",
  subject: "Your receipt",
  html: "<p>Thanks! Your receipt is attached.</p>",
  attachments: [
    {
      filename: "receipt.pdf",
      content: pdfBase64,           // base64 string of the file bytes
      contentType: "application/pdf",
    },
  ],
});

A file you already hold as bytes becomes base64 with btoa/Buffer, or read one straight from env.STORAGE and encode it. Content pulled from R2:

const obj = await env.STORAGE.get("invoices/42.pdf");
const bytes = new Uint8Array(await obj.arrayBuffer());
let bin = "";
for (const b of bytes) bin += String.fromCharCode(b);
const content = btoa(bin);
await env.EMAIL.send({
  to, subject: "Invoice #42",
  text: "Invoice attached.",
  attachments: [{ filename: "invoice-42.pdf", content, contentType: "application/pdf" }],
});
Limits: up to 20 files and about 6 MB of attachments total per email (the base64 payload is capped at 8 MB). For anything larger, upload the file to env.STORAGE and email a link instead. Attachments count as part of the same message against your workspace's email limits.

Sending from your own domain

By default mail goes out from a per-app address on a Cloudrizz domain. To send under your own brand, verify a domain once, from the app's Email sender settings in the dashboard, or with the manage_email_sender tool. Add the DNS records it shows you, and every app in your workspace can then send from that domain.

Sending from your own domain works for every workspace. A verified domain also covers its subdomains, such as news.yourdomain.com.

New domains warm up. Mail providers distrust a domain that suddenly sends a lot, so for its first 14 days after verification a domain sends a growing amount per day, across all your apps: 100 a day at first, then 300, 1,000, 3,000 and 10,000, rising every few days. After that only the normal limits apply. Sign-in and password emails are never held back. If a send would go over, send() says so and it doesn't count toward your usage.

  • Set a default from for the app (e.g. noreply@yourdomain.com), or pass from on any individual send() call.
  • Any local part on a verified domain works, hello@, billing@, team@, with no need to verify each one.
  • Verify more than one domain if you send under multiple brands, and choose which to use per message.
Building a multi-tenant app where your own customers send from their domains? Your app can register and verify their domains at runtime, straight from your code, see Let your customers use their own domains below.

Let your customers use their own domains

The section above is for domains you own. But if you're building a multi-tenant app, say a booking platform where each client wants confirmation emails to come from their brand (e.g. noreply@eikenga.no, not your domain), your app can register and verify each customer's domain at runtime, entirely from your own code. Your customer never touches this dashboard; they only add a few DNS records to their own domain.

Four methods on env.EMAIL drive the whole flow:

MethodWhat it does
env.EMAIL.addDomain(domain)Registers domain for this app and returns the DNS records the customer must add. Status starts as "pending".
env.EMAIL.verifyDomain(domain)Re-checks the domain's DNS and flips its status to "verified" once the records resolve. Call it after the customer has added the records.
env.EMAIL.listDomains()Returns { domains: [...] }, every domain this app has registered, each with its current status.
env.EMAIL.removeDomain(domain)Removes a domain from this app. Returns { removed: true, domain }.
  1. Register the domain. When your customer enters their domain in your app's UI, call addDomain. You get back the DNS records to show them.
    // api/customer-domains.js, your customer submits "eikenga.no"
    const result = await env.EMAIL.addDomain("eikenga.no");
    // result = {
    //   domain: "eikenga.no",
    //   status: "pending",
    //   dnsRecords: [
    //     { type: "TXT", name: "…", value: "…" },   // DKIM / SPF
    //     { type: "MX",  name: "…", value: "…", priority: 10 },
    //     …
    //   ],
    //   createdAt: 1737000000000,
    //   verifiedAt: null,
    // }
    return Response.json({ records: result.dnsRecords });

    Show every entry in dnsRecords to your customer verbatim, type, name, and value (plus priority for MX records). They add each one at their DNS provider.

  2. Verify once they've added the records. DNS can take anywhere from a minute to a few hours to propagate, so verifyDomain is safe to call repeatedly, behind a "Check status" button, or from a scheduled job.
    const check = await env.EMAIL.verifyDomain("eikenga.no");
    if (check.status === "verified") {
      // Ready, this domain can now send.
    } else if (check.status === "pending") {
      // DNS hasn't propagated yet. Ask them to wait and check again.
    } else {
      // "failed", the records don't match. Have them re-check against dnsRecords.
    }
  3. Send from the verified domain. Once the status is "verified", set it as the from on any send. Any local part works, you don't verify noreply@, hello@, etc. separately.
    await env.EMAIL.send({
      from: "Eikenga <noreply@eikenga.no>",
      to: "buyer@example.com",
      subject: "Your booking is confirmed",
      html: "<p>See you on the 20th.</p>",
    });

These methods throw on failure (they don't return an error object), so wrap them in try / catch and surface the message to your customer. addDomain throws if:

  • you've hit the per-app domain limit (remove one first), or
  • the domain is a public mailbox provider (gmail.com, outlook.com, …), those can never be registered as sending domains.

A from is only accepted once its domain is verified; an unverified or unknown sender domain is rejected. That, plus the DNS records being under the customer's control, is what stops anyone sending as a domain they don't own.

Preview-safe rewriting still applies (see below): addDomain and verifyDomain work against real DNS on any deploy, so you can build and test the whole flow on a preview, but actual mail only reaches your customers' recipients from a production deploy.

Receiving email

Every app can receive email at anything@your-app.cloudrizz.app. Add an api/email.js that exports onEmail, deploy it to production, and each message that arrives is handed to it. Use it for support inboxes, replies to notifications, forwarding rules, or importing invoices sent by email.

// api/email.js
export async function onEmail(message, env, ctx) {
  if (message.spam) return; // flagged by the spam filter, still delivered

  await env.DB.prepare(
    "INSERT OR IGNORE INTO tickets (mail_id, sender, subject, body) VALUES (?, ?, ?, ?)",
  ).bind(message.id, message.from?.address, message.subject, message.text).run();

  // Attachments can only be read while onEmail runs: copy what you keep.
  for (const a of message.attachments) {
    await env.STORAGE.put("tickets/" + message.id + "/" + (a.filename || a.id), await a.read());
  }
}
FieldWhat it is
idA stable id. Delivery is at-least-once, so use it to skip a message you already handled.
recipientsThe app addresses the message was sent to.
from, to, cc, replyTo{ address, name }; to, cc and replyTo are lists.
subject, date, messageId, inReplyToFrom the message headers.
text, htmlThe bodies. Never put html on a page unsanitized: mail HTML can carry scripts and tracking images.
attachments[{ id, filename, contentType, size, contentId, inline, read() }]; read() returns the bytes. Inline images have a contentId.
spam, virus, verdictsSpam and virus scan results, plus SPF, DKIM and DMARC checks of the sender.
raw()The whole original message.
  • When the virus scan fails, the message still arrives but its attachments don't (attachmentsWithheld is true).
  • If onEmail throws, the message is kept and marked as failed; your assistant can run it again after the handler is fixed.
  • By default every address at the app is accepted. Your assistant can limit it to a list (e.g. only support and billing); the rest is turned away.
  • Previews never receive real email. Ask your assistant for a test delivery: it drops a made-up message into onEmail on a preview or on production.
  • An api/email.js without onEmail stays a normal route at /api/email.

The app page's Email tab shows the address, whether the app receives email, and the latest messages with what happened to each.

Receiving on your own domain

Mail can also arrive at an address on your own domain, like support@yourdomain.com. The domain must be one of your verified sending domains (above) or a subdomain of it, and its MX record must point at inbound-smtp.eu-west-1.amazonaws.com (priority 10).

If the domain already has mailboxes (Google Workspace, Outlook, ...), pointing its MX here moves all of its mail to your app. Use a subdomain instead, e.g. in.yourdomain.com.
  • Your workspace's domain: add it on the app's Email tab (Incoming email, "Your own domains") or ask your assistant. It shows the MX record and checks it; the domain starts receiving once all its MX records point here.
  • Your customers' domains, e.g. every customer of a helpdesk app gets support@theirdomain.com: register and verify the domain with env.EMAIL.addDomain() (see above), then turn on receiving from your code.
const r = await env.EMAIL.receiveDomain("in.theirdomain.com");
// r.status: "pending" until the MX record is in place, then "active"
// r.records: the MX record to show your customer; r.problem: what's missing
await env.EMAIL.receivingStatus("in.theirdomain.com"); // check again
await env.EMAIL.stopReceiving("in.theirdomain.com");

message.recipients tells your onEmail handler which address, and so which customer, a message was for. Removing the sending domain stops receiving on it at once.

Preview-safe by default

On a preview or branch deploy, email is automatically made safe: the recipient is rewritten to the deploying user, the subject is prefixed with [PREVIEW], and a banner is added to the body. Real recipients only receive mail from a production deploy, so testing a flow never emails your customers.

Limits

Email is counted for all your workspace's apps together, both sent and received messages (mail the spam or virus scan flags isn't counted). A sent message counts once per recipient (to, cc and bcc). Email is paid as usage ($0.60 per 1,000). With a card it never stops; without one it stops with the apps when the month's free $1 is used. A short-window rate limit and a daily ceiling per app also apply to sending, and at most 100 messages per sender per hour are received per app, to contain bugs and abuse. Received messages can be up to 35 MB, and stored mail counts toward your storage; without a card, mail is refused while your workspace's storage is full. See Billing & usage.

Keeping received mail. Received mail is kept until you delete it. Your assistant can set a retention period instead (manage_app_mail, action set_rules, retentionDays): mail older than that is deleted every night, with its attachments, unless it sits in a mailbox, where its users decide (mailbox Trash empties itself after 30 days).

Sending reputation. If too many of an app's messages bounce or are reported as spam over a week (8% bounces or 0.3% spam reports, once it has sent to 100 people), its sending is paused to protect deliverability for everyone, and send() says so. Send only to people who asked for your mail, and contact support to resume.

Auth emails (verification, password reset, 2FA codes) sent by env.AUTH go through this same channel, you don't call env.EMAIL yourself for those.