Skip to content

How to Receive Email in Your App With an API

7 min read

A pop-art comic hand holding a white envelope with green dots toward an open blue mailbox with its flag raised, in front of a coral burst on a yellow background.

An inbound email API turns mail sent to an address you own into data your app can read: a webhook fires when a message arrives, and one HTTPS call returns the body, headers and attachments. You don't run a mail server, poll an IMAP mailbox or parse MIME yourself.

Apps receive mail for plenty of reasons. A help desk turns customer replies into tickets. A marketplace lets buyers answer a seller's notification from their inbox. An expense tool takes forwarded receipts. An AI agent needs an address people can write to. This guide walks through receiving with Mailfully, from the first test address to reading attachments in code. The plan figures below are the ones on our pricing page in November 2026.

What an Inbound Email API Does

Sending mail is one request out. Receiving is the reverse, and it has more moving parts. Some server has to accept SMTP connections for your domain, check the message for spam and viruses, store it, tell your app it arrived, and give you a clean way to read it.

With Mailfully, that flow looks like this:

  • Mail arrives at an address on a domain you've set up for receiving.
  • Our servers scan it for spam and viruses and store one copy for your organization.
  • Your endpoint gets an email.received webhook with the message metadata.
  • Your code calls GET /v1/emails/receiving/{id} for the body, headers and authentication results.
  • Attachments come from GET /v1/emails/receiving/{id}/attachments, each with a download link.

Receiving is catch-all. Every address at a receiving domain is accepted, so support@, orders@ and ticket-4821@ all reach you without any per-address setup. Each email lists the addresses it was sent to in received_for, and that is the field to route on.

Two Ways to Get an Address

You can receive at a hosted address or at your own domain. The hosted address needs no DNS, which makes it the quickest way to try receiving. Your own domain is what you give customers.

The hosted address looks like anything@k7q2m9xa.mailfully.app. The eight-character label is random and assigned the first time you turn the address on, and it stays the same if you turn it off and on again. An owner or admin turns it on in the dashboard under Settings, Hosted address. It works on every plan, Free included.

Your own domain works on Starter, Growth and Scale. The domain has to be verified for sending first. Then you turn receiving on with one API call and publish one MX record.

Receive on Your Own Domain

Turn receiving on with PATCH /v1/domains/{id}, using a key with the send scope:

bash
curl -X PATCH https://api.mailfully.com/v1/domains/dom_01J1PZ3M8Q7VXCK4T2R9WFH6BD \
  -H "Authorization: Bearer $MAILFULLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "receiving": true }'

The response is the domain with receiving: true and one new MX entry at the end of records. Publish that record at your DNS provider, on the domain name itself, and mail starts arriving once it resolves. The domain's page in the dashboard shows the same record and tells you whether it's published.

One check protects your existing mailboxes. Before turning receiving on, Mailfully looks up the domain's current MX records. If any of them points at another provider, such as Google Workspace or Microsoft 365, the call is refused with 409 mx_conflict. A second MX record beside your current provider's would split your incoming mail between the two. Use a subdomain instead: add inbound.yourcompany.com as its own domain, verify it, and turn receiving on there. Mail to yourcompany.com keeps going where it goes today.

The other refusals are short. Free returns 403 receiving_requires_paid_plan (use the hosted address there), a domain that isn't verified yet returns 409 domain_not_verified, and a DNS lookup that timed out returns 503 dns_lookup_failed, with nothing changed, so you can retry.

Get Each Message by Webhook

Subscribe an endpoint to email.received in the dashboard, under Webhooks. The dashboard shows the signing secret once, when you create the endpoint. Store it as MAILFULLY_WEBHOOK_SECRET.

The payload carries metadata, not the body:

json
{
  "type": "email.received",
  "created_at": "2026-11-27T14:12:08.000Z",
  "data": {
    "email_id": "inb_01JQ4Z8M2V6KD3N7R9T1WXYB5C",
    "from": "ada@example.com",
    "to": ["support@inbound.acme.com"],
    "cc": [],
    "bcc": [],
    "received_for": ["support@inbound.acme.com"],
    "message_id": "<CAF3x9k2@mail.example.com>",
    "subject": "Order 1234 arrived damaged",
    "attachments": [
      {
        "id": "att_01JQ4Z8M3A5E7G9H1K2M4P6R8S",
        "filename": "photo.jpg",
        "content_type": "image/jpeg",
        "content_disposition": "attachment",
        "content_id": null
      }
    ],
    "spam": "PASS",
    "virus": "PASS"
  }
}

Route on received_for, not to. The to and cc lists come from the message headers, which the sender writes. received_for comes from the SMTP envelope, so it includes blind-copied addresses and any other recipient the headers never showed. bcc is always empty, because the receiving side is never told who was blind-copied.

Every delivery is signed with three headers: webhook-id, webhook-timestamp and webhook-signature. Verify the raw request body before you trust it. The webhooks guide has a Node verifier you can copy, and it needs only Node's crypto module. Delivery is at least once, so the same event can arrive twice. For received mail, webhook-id is the email's inb_ id and stays the same on every retry, which makes it a natural key for dropping duplicates.

Read the Body and Attachments

Every receiving endpoint needs a key with the read:inbound scope. A send key gets 403 insufficient_scope. Scopes can't be added to an existing key, so create a new one in the dashboard under API Keys and tick Read received email.

Here is a Next.js route handler that verifies the webhook, fetches the message and downloads its attachments:

ts
// app/api/inbound/route.ts
import { verifyMailfullyWebhook } from "@/lib/mailfully-webhook";

export const runtime = "nodejs";

const API = "https://api.mailfully.com/v1/emails/receiving";
const auth = { Authorization: `Bearer ${process.env.MAILFULLY_INBOUND_KEY}` };

export async function POST(req: Request): Promise<Response> {
  const rawBody = await req.text();
  const headers = {
    "webhook-id": req.headers.get("webhook-id") ?? "",
    "webhook-timestamp": req.headers.get("webhook-timestamp") ?? "",
    "webhook-signature": req.headers.get("webhook-signature") ?? "",
  };
  const secret = process.env.MAILFULLY_WEBHOOK_SECRET ?? "";
  if (!verifyMailfullyWebhook({ secret, headers, rawBody })) {
    return new Response("invalid signature", { status: 401 });
  }

  const event = JSON.parse(rawBody);
  if (event.type !== "email.received") return new Response(null, { status: 204 });

  const id = event.data.email_id;
  const email = await fetch(`${API}/${id}`, { headers: auth }).then((r) => r.json());
  console.log(email.subject, email.authentication?.dmarc, email.text);

  const files = await fetch(`${API}/${id}/attachments`, { headers: auth }).then((r) => r.json());
  for (const file of files.data) {
    if (!file.download_url) continue; // null when the message carried a virus
    const bytes = await fetch(file.download_url).then((r) => r.arrayBuffer());
    console.log(`saved ${file.filename}, ${bytes.byteLength} bytes`);
  }

  return new Response(null, { status: 204 });
}

If you use the mailfully npm package, mailfully.emails.receiving.get(id) returns the same message as a { data, error } pair.

The detail response has html and text (either is null when the message had no such part), every header in order, the parsed reply_to, in_reply_to and references, and an authentication object with SPF, DKIM and DMARC results. By default, inline images in html are swapped from cid: links to data: URIs, so the HTML renders on its own. Pass html_format=cid to keep the original links.

Download links last an hour at most, and expires_at gives the exact time. Ask for a fresh link when you need the file again, rather than storing one. The raw field gives a link to the original .eml file, which helps when you want to archive the message exactly as it arrived.

Check Who Really Sent It

Mailfully doesn't reject mail for failing SPF, DKIM or DMARC. It records the results and leaves the decision to you, because a help desk and a receipt parser need different rules.

Anyone can type any address into a From header. So if your app acts on the sender's address (opening a ticket under their account, attaching a receipt to their profile, resetting anything), check authentication.dmarc first and treat anything but PASS with suspicion.

Spam is kept, too, and marked with spam: "FAIL". Filter on it yourself, or list only spam with GET /v1/emails/receiving?spam=true. A message with virus: "FAIL" keeps its metadata, but its body, headers, raw file and attachments are never stored.

Reply in the Same Thread

A reply is an ordinary send through POST /v1/emails. To keep it in the sender's thread, copy the received message_id into the In-Reply-To and References headers:

js
await fetch("https://api.mailfully.com/v1/emails", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MAILFULLY_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    from: "Acme Support <support@inbound.acme.com>",
    to: email.from,
    subject: `Re: ${email.subject}`,
    text: "Sorry about the box. A replacement ships today.",
    headers: {
      "In-Reply-To": email.message_id,
      References: [...email.references, email.message_id].join(" "),
    },
  }),
});

Mail clients read those two headers to show the reply under the original message.

What Receiving Costs

Each received email counts once, however many of your addresses it was sent to. Spam and virus failures are never counted, and received mail never counts toward daily sending limits.

On the paid plans, received mail shares the plan's monthly emails with sent mail:

  • Starter: $5 a month for 10,000 emails, kept 30 days.
  • Growth: $19 a month for 50,000 emails, kept 30 days.
  • Scale: $99 a month for 500,000 emails, kept 90 days.

Past the allowance, received mail is billed like sent mail, at $0.40 per 1,000. Mail that arrives after a plan reaches five times its allowance is stored but locked until your usage is back under it, and locked mail is never billed.

Free works differently from December 1, 2026. It gets 100 received emails a month on their own count, separate from the 3,000 emails you can send, so receiving never uses up your sending allowance. Past 100, new mail is deleted on arrival until the next month starts. Free receives at the hosted address only, and from December 8 it keeps received mail for 7 days. See the pricing page for every plan side by side.

Start Receiving

Turn on the hosted address in Settings, send it a message from your own mail account, and list what arrived with a read:inbound key:

bash
curl https://api.mailfully.com/v1/emails/receiving \
  -H "Authorization: Bearer $MAILFULLY_INBOUND_KEY"

The receiving guide has every field and refusal, and the inbound email page sums up the limits. If you're building for an AI agent, agent inboxes covers giving each agent an address of its own.

Try Mailfully free at dashboard.mailfully.com/register.

Mailfully is a transactional email API for developers. Your app sends receipts, password resets and sign-in links with one API call, and can receive email by webhook. 3,000 emails a month are free, and paid plans start at $5. Start free.

See pricingRead the quickstart