Learn

How to receive and parse inbound email in your app

Updated October 18, 2026

In short

To receive email in an app, point your domain's MX record at a service that accepts the mail, parses it, and delivers it to your code as JSON through a webhook or API. It's simpler and safer than polling a mailbox over IMAP or running your own mail server - and a good service tells you whether the sender is authentic.

Three approaches

There are three ways to get mail into your application, and the right one depends on how much of the mail system you want to own.

ApproachHowTrade-off
IMAP pollingLog in to a mailbox and fetch new messages on a timerSlow, fragile credentials, you parse MIME yourself
Your own mail serverRun Postfix/Exim, pipe mail to a scriptFull control, but you run and secure an SMTP server
Inbound email APIMX points at a provider that posts JSON to your webhookLeast code; choose a provider that checks sender authentication

What arrives

How mail sent to your domain reaches your applicationSMTPverdictJSONSendersupport@acme.comYour MXsp.acme.com MX 10AuthenticatedSPF · DKIM · DMARCParsedheaders, bodies,attachment infoYour webhookemail.receivedYour appcheck the verdict,then act

Swipe the diagram to see the rest

Mail arriving at your own domain. The MX record points at us, the message is authenticated and parsed on receipt, and your handler gets JSON with the verdict already attached - so it can decide whether to trust the sender before acting on what they asked for.

A parsed inbound message is more than a body. The pieces you will actually build on are the ones people forget to ask about:

An inbound email API gives you the envelope recipient, From, To, CC, subject, text and HTML bodies, headers and attachment metadata as JSON - no MIME parsing on your side.

Never trust the From line

This is the part that turns a reply-by-email feature into a vulnerability. The From header is written by whoever composed the message, and nothing about receiving it proves the claim. If an action in your application depends on who sent the mail, the authentication verdict is what you check - not the address.

Anyone can write any address in From. Before an automation acts on received mail - creating a ticket, resetting something, forwarding data - check that the sender's domain authenticated the message. Sendpository checks SPF, DKIM and DMARC on arrival and gives every message a sender_verdict of verified, failed, unverified or unchecked.

Handling email.received
if (event.type === "email.received" && event.data.sender_verdict === "verified") {
  await openTicket(event.data.from, event.data.subject, event.data.text_preview);
}

Other things to get right

The rest is mostly about accepting that mail is messy and arrives more than once.

  • Deduplicate - mail servers retry, so the same message can arrive twice.
  • Treat HTML bodies as hostile: render them sandboxed, block remote images.
  • Cap sizes and storage; one sender shouldn't be able to fill your database.

Questions

What is an MX record?

A DNS record naming the mail server that accepts email for a domain. Pointing a (sub)domain's MX at an inbound email service is how mail for it reaches your app.

Can I receive email on a subdomain only?

Yes, and it's the safest way: receive on inbound.yourdomain.com or sp.yourdomain.com and leave your company mailbox's MX on the main domain untouched.

Related

Send your first email in minutes

6,000 emails a month (up to 200 a day), free forever. No card needed.