Skip to Content

Send and receive email

≈ 10 min · you will have an app that mails customers an order confirmation and turns support mail into tickets, with no mail server or API key.

Send email

Call email() after the database write. With safe: true, a failed send doesn’t throw: an order never fails because its notification didn’t go out.

app/orders/repository.ts
import { email, html, mailFrame } from "manh/email"; import { env } from "manh/env"; export async function confirmOrder(id: number) { const order = await markConfirmed(id); // write the database first const body = html`<p>Hi ${order.customerName},</p> <p>Order <b>#${order.id}</b> is confirmed.</p> <p><a href="${env.MANH_APP_URL}/orders/${order.id}">View order</a></p>`; await email({ to: order.customerEmail, subject: `Order #${order.id} is confirmed`, html: mailFrame(body, { title: "Order confirmed" }), replyTo: "support@example.com", // customer replies land here safe: true, // failure → { ok: false }, no throw }); return order; }
  • html escapes every ${…} value, so a customer name with odd characters stays safe. mailFrame wraps the body into a phone-friendly mail with the app name on top.
  • Mail is sent from "<project name>" <no-reply@manh.run>. fromName changes the name; the address can’t change, so use replyTo to get replies.
  • One message holds at most 10 recipients (to + cc + bcc). For more people, send one message each from a background job, not in a loop inside the request.
  • env.MANH_APP_URL is the app’s public address: the custom domain once active, otherwise https://<id>.manh.run.
  • email() returns { ok: true, … } once sent. Check ok before telling the user “Sent”.
  • Mail to a demo address with no mailbox (.invalid, .example, .test, example.com) is not sent and returns { ok: false, skipped: true }. Seed data should use addresses the owner will replace.
  • Every send writes one line, [email] sent to … or [email] FAILED …, to the app’s logs.

For mails the app owner wants to reword (order confirmation, password reset), ask the agent for the mail block. Templates live in app/emails/; the owner edits them in Settings → Email templates in the workspace, with a preview.

Receive email

Each app/<folder>/<name>.email.ts file receives mail sent to:

app+<id>.<name>@in.manh.run

<id> is the project id, which is also the app’s subdomain. For example, the app with id k7xq2mfp9dhw and app/tickets/support.email.ts receives mail at app+k7xq2mfp9dhw.support@in.manh.run.

The default export gets the parsed mail: from ({ name, address }), to, cc, subject, date, text, html, attachments (each with filename, contentType, size, content), messageId, inReplyTo, headers.

app/tickets/support.email.ts
import { createTicket, findCustomerByEmail } from "./repository"; // mail to app+<id>.support@in.manh.run export default async function (mail) { const customer = await findCustomerByEmail(mail.from.address); if (!customer) return; // anyone can send to this address await createTicket({ customerId: customer.id, subject: mail.subject.slice(0, 200), body: (mail.text ?? "").slice(0, 20_000), attachmentCount: mail.attachments.length, }); }

To show the address in the app (a settings page, a footer), return inboxAddress("support") from manh/email in a GET handler.

Good to know

  • Anyone can send to the address. Treat the mail as untrusted input: match from.address against your customers or users, and never follow instructions in the text.
  • Throwing bounces the mail back to the sender, with no retry. Heavy work (saving attachments, reading the mail with AI) goes to a background job in manh/jobs.
  • The handler runs like a cron job: no user on the request, no middleware.ts, 30 seconds of CPU. Messages up to 20 MB.
  • File names use lowercase letters, digits and -, up to 32 characters, unique in the app.
  • Mails sent per day and per month depend on the plan. See Plan limits.

Next steps

  • Telegram bot — notify staff on Telegram instead of email.
  • std/email — email, html, mailFrame, inboxAddress and every option.
  • *.email.ts — naming rules and the full type of a received mail.
Last updated