Saltar al contenido
Outer
Esc
↑↓navegar↵abrir⌘Jvista previa
En esta página

Send email from your app

Notify the app's owner and collaborators over HTTP with no key; Resend for anyone else.

Verdict: notify the app’s own people with no key; Resend for everyone else. Every deploy injects two platform-provided Worker env vars, OUTER_NOTIFY_URL and OUTER_NOTIFY_TOKEN. Server code calls that URL after a D1 insert (contact form, new signup, alert) and Outer emails the app’s owner and opted-in collaborators. SMTP ports 25/465/587 are blocked at the fleet edge, and Void’s sendEmail needs Cloudflare’s send_email binding, which is not an accepted deploy key on Outer: a config declaring it fails deploy validation naming the key. The person-facing guide is Send email from your app.

Notify the owner and collaborators

Recipients are never caller-controlled: only the app owner (while their console toggle is on) and collaborators who opted in themselves. Never pass a recipient address — the call carries only a subject and a body:

// routes/api/contact.ts
import { defineHandler } from "void";
import { env } from "cloudflare:workers";

export const action = defineHandler(async (c) => {
  const body = await c.req.json<{ name: string; message: string }>();
  if (typeof body.name !== "string" || typeof body.message !== "string") {
    return c.json({ errors: { message: "Tell us your name and message." } }, 422);
  }
  // ... validate, insert into D1 ...
  const res = await fetch(env.OUTER_NOTIFY_URL, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${env.OUTER_NOTIFY_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      subject: `New contact from ${body.name}`,
      text: body.message,
    }),
  });
  if (!res.ok) return c.json({ errors: { message: "Couldn't send — try again." } }, 422);
  return {};
});

Rules: subject is one line (1–150 chars, no control characters), text is 1–10,000 chars, the request body caps at 16 KiB. Every email opens with the fixed line This message was sent by the app <slug>.outer.now, not by Outer. and signs as <brand> via Outer (a brand reaching for the platform’s own name falls back to <slug> via Outer). The daily budget belongs to the owner’s account and is shared across everyone subscribed: 20 emails on Free, 500 on Pro, counted per delivered recipient. Over the cap the call answers 429; past half the platform’s monthly email budget (shared with sign-in codes) or on unconfigured platforms, 503 notify_unavailable. OUTER_NOTIFY_URL and OUTER_NOTIFY_TOKEN are platform-provided: never set them as secrets (refused with a clear message), never commit them. Tokens rotate when a collaborator leaves or the owner rotates in the console; the app must redeploy to pick up the fresh token, and a stale token answers notify_token_rotated. Unsubscribing happens in the console’s Notification emails card, never in code.

Everyone else: Resend with your own key

Mail to anyone outside the owner/collaborators circle — customer receipts, digests, invites — goes through an HTTP email service such as Resend, with the app’s own key.

Store the key

Never commit it. Set it outside the code and read it as a Worker env var on the next deploy (Secrets):

  • set_secret {app, key: "RESEND_API_KEY", value: "re_…"} (MCP), or Console → Secrets.

Send over HTTP

// routes/api/invite.ts
import { defineHandler } from "void";
import { env } from "cloudflare:workers";

export const action = defineHandler(async (c) => {
  const body = await c.req.json<{ to: string }>();
  if (typeof body.to !== "string" || !body.to.includes("@")) {
    return c.json({ errors: { to: "Enter a valid email address." } }, 422);
  }
  const res = await fetch("https://api.resend.com/emails", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${env.RESEND_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      from: "Grocery <list@updates.example.com>",
      to: body.to,
      subject: "You're invited",
      text: "Join our grocery list: https://grocery.outer.now",
    }),
  });
  if (!res.ok) return c.json({ errors: { to: "Send failed — check the address." } }, 422);
  return {};
});

Use a sender domain you control (verified in Resend), and validate the recipient before sending. Bounced spam burns the domain.

Plan for inbound

Inbound email needs a receiving service in front (Resend inbound, Cloudflare Email Routing on your own zone) forwarding to an app route as HTTP. There is no MX path into <slug>.outer.now.

¿Te ha resultado útil esta página?