Payload Structure
Inbound emails are posted to your inbound domain’s forwarding URL as a JSON array of events. Each event contains a relay message with the email’s content:Payloads are always a JSON array of events. A single delivery may contain one or more events, so loop over the array instead of reading only the first item.
Field Reference
There is no
attachments field. Attachments are only available inside email_rfc822. See Raw MIME Parsing and Attachments.
Reading the Payload
relay is one event.msys.relay_message object.
Sender Information
From Address
The relay message provides two sender fields:msg_from: the envelope sender (SMTPMAIL FROM). For mailing lists and bulk senders this is often a bounce address, not the person who wrote the email.friendly_from: the display name and address from theFromheader. This is usually the address you want to show or reply to.
friendly_from:
Reply-To Address
The Reply-To address is in thecontent.headers array, when the sender set one (getHeader is defined under Email Headers):
Recipients
The relay message provides:rcpt_to: the envelope recipient, the address on your inbound domain that received the emailcontent.to: the addresses from theToheadercontent.cc: the addresses from theCcheader, when there are any
rcpt_to to decide which of your addresses the email was meant for. It can differ from the To header, for example when your address was in Bcc or the email was forwarded.
BCC recipients are not visible in received emails. If your address was BCC’d, it appears only in
rcpt_to.Subject Line
The subject is incontent.subject:
content.headers under Subject.
Email Body
Plain Text and HTML
Emails can contain plain text, HTML, or both. The bodies are incontent.text and content.html, and either one can be missing:
Extracting Text from HTML
Handling Quoted Content
Strip quoted replies to get just the new content:Email Headers
Standard Headers
Headers are incontent.headers as an array of objects, each with a single key (the header name) and a string value. A header that appears several times in the email, such as Received, appears several times in the array. Which headers are present depends on the sender. Common ones:
Header names keep the capitalization the sender used (
Message-ID, Message-Id), so look them up case-insensitively:
Message-ID is also the right key for deduplication: the same email can be delivered to your endpoint more than once, so store the Message-IDs you have processed and skip repeats.
Custom Headers
Access any header using the helper:Date and Time
Sent Timestamp
The original send time is in theDate header:
Date header is set by the sender’s client and can be missing or wrong. Record your own received time as well.
Character Encoding
content.subject, content.text and content.html are JSON strings, so you read them as ordinary Unicode text. If you need exact control over how a part’s declared charset is decoded, parse email_rfc822 with a MIME library, which reads each part’s charset and Content-Transfer-Encoding itself.
Multipart Emails
Most emails are multipart: a plain text version, an HTML version, and possibly attachments and inline images. The payload breaks out only the bodies:email_rfc822.
Raw MIME Parsing
content.email_rfc822 holds the complete raw message. Parse it with a MIME library when you need attachments, inline images, or MIME structure that the structured fields don’t cover. When content.email_rfc822_is_base64 is true, base64-decode the field first.
Parsing Examples
Extract Email Signature
Detect Email Client
Parse Structured Data
Handling Edge Cases
Empty Content
email_rfc822 before discarding it.
Malformed Addresses
Related Topics
Inbound Setup
Create an inbound domain and forwarding URL
Attachments
Extract files from the raw message
Reply Tracking
Track conversation threads
Routing
Route emails based on content