An inbound email parse webhook delivers email sent to your domain straight into your application as an HTTP POST. You point an MX record at your email provider, the provider receives and parses each message, and your webhook gets the sender, recipients, subject and attachments. From there your code can create a support ticket, post a reply in a comment thread, or hand the message to an agent.
How inbound email parsing works
- DNS. You add an MX record for a domain or subdomain, for example
replies.acme.com, pointing at the provider’s inbound servers. - Receiving. A sender’s mail server looks up that MX record and delivers the message over SMTP, as it would to any mailbox.
- Parsing. The provider splits the raw MIME message (RFC 5322 headers plus MIME parts) into text, HTML, headers and attachments, and stores them.
- Webhook. The provider POSTs an event to your URL, signed so you can prove where it came from.
- Your code verifies the signature, fetches what it needs, and acts.
A MX record only affects the exact name it is set on. Setting one on replies.acme.com does not touch the mailboxes on acme.com.
Best practices for receiving email in an app
- Use a subdomain.
replies.acme.comorin.acme.comkeeps parsing separate from your staff mailboxes. - Encode routing in the address.
reply+t_8f2a@replies.acme.comtells you which ticket or thread a reply belongs to without guessing from the subject. - Verify every webhook. Anyone can POST to a public URL. Check the signature and reject old timestamps.
- Answer fast, work later. Return 200 within a few seconds and do the slow work in a queue. Slow handlers cause retries.
- Be idempotent. Webhooks can arrive more than once. Store the email id and skip ones you have already handled.
- Strip quoted history. Replies carry the whole previous thread. Keep the new text above the quote line for display.
- Never trust the From header alone. It can be forged. Check authentication results before you let an email trigger anything sensitive.
Example inbound email
A customer replies to a notification:
From: Sam Buyer <sam@example.com>
To: reply+t_8f2a@replies.acme.com
Subject: Re: Order 1042 shipped
In-Reply-To: <order-1042@acme.com>
The box arrived damaged. Photo attached.
On Mon, Acme <orders@acme.com> wrote:
> Your order 1042 has shipped.
Your app should pull t_8f2a from the address, attach the new text and the photo to ticket 8f2a, and ignore the quoted part.
Choosing an address scheme
| Scheme | Example | Good for |
|---|---|---|
| Fixed address | support@in.acme.com |
One shared inbox, such as a help desk |
| Plus addressing | reply+t_8f2a@in.acme.com |
Replies that belong to one thread or record |
| Catch-all per customer | invoices-42@in.acme.com |
Forwarding documents into one customer’s account |
Use a random token in the address, not a database id. A guessable address lets anyone post into someone else’s thread. The In-Reply-To and References headers can confirm a match, but some mail clients drop them, so the address is the more reliable key.
Receiving email with Mailcandor
Inbound email is included on every Mailcandor plan. Point the MX record for your domain or subdomain at inbound-smtp.us-east-1.amazonaws.com with priority 10, add the domain in Mailcandor, and subscribe a webhook to email.received. The webhook carries metadata: email_id, from, to, cc, subject, message_id and a list of attachments. The body is fetched with GET /v1/emails/receiving/{id}.
Deliveries are signed with Standard Webhooks. This Express handler verifies the signature, fetches the body and hands it on:
import express from 'express';
import crypto from 'node:crypto';
const app = express();
const KEY = process.env.MAILCANDOR_KEY;
const SECRET = Buffer.from(process.env.MAILCANDOR_WEBHOOK_SECRET.replace(/^mcws_/, ''), 'base64');
function verify(req) {
const id = req.get('webhook-id');
const ts = req.get('webhook-timestamp');
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
const expected = crypto.createHmac('sha256', SECRET)
.update(`${id}.${ts}.${req.body}`).digest();
return (req.get('webhook-signature') ?? '').split(' ').some((part) => {
const sig = Buffer.from(part.replace(/^v1,/, ''), 'base64');
return sig.length === expected.length && crypto.timingSafeEqual(sig, expected);
});
}
app.post('/webhooks/mailcandor', express.raw({ type: 'application/json' }), async (req, res) => {
if (!verify(req)) return res.status(401).end();
const event = JSON.parse(req.body);
res.status(200).end(); // answer first, then work
if (event.type !== 'email.received') return;
const r = await fetch(`https://api.mailcandor.com/v1/emails/receiving/${event.data.email_id}`, {
headers: { Authorization: `Bearer ${KEY}` },
});
const email = await r.json();
const route = email.to.find((a) => a.startsWith('reply+'))?.match(/^reply\+([^@]+)@/)?.[1];
await handleInbound({ route, from: email.from, subject: email.subject, text: email.text, html: email.html });
});
app.listen(3000);
handleInbound is your own function, such as adding a comment to a ticket. For attachments, call GET /v1/emails/receiving/{id}/attachments; each item has a download_url that works for one hour without an API key. Received messages are also listed at GET /v1/emails/receiving, so you can catch up if your endpoint was down. The single-email response also includes headers and reply_to, which you need for loop checks and for replying to the right address. Failed webhook deliveries are retried up to 8 times over about 28 hours and can be replayed.
In production, put the work after the 200 into a queue rather than running it in the request. The example keeps it inline to stay short.
Common pitfalls
- Parsing JSON before verifying. Signature checks need the raw body bytes. Body parsers that re-serialize JSON change them.
- MX on the root domain by accident. This moves all your company mail. Double-check the record name.
- Mail loops. If your app auto-replies to inbound mail, and the sender auto-replies too, they will reply forever. Skip messages with an
Auto-Submittedheader (RFC 3834) and never auto-reply to your own addresses. - Treating HTML as safe. Inbound HTML is untrusted input. Sanitize it before you render it in your app.
- Timeouts. Doing OCR or AI calls inside the request causes retries and duplicates. Queue it.