Storing and Retrieving Messages
Storing and Retrieving Messages
When storing an email through a store() action in a Route, you can choose to be notified when the message is stored by including a URL with the notify parameter when setting up the store action or you can retrieve the message later by searching for the message through the Events API and retrieving it through the Messages API
When you set a URL to be posted when the message is received:
(store(notify="http://mydomain.com/callback") or retrieve the message later through a GET request to the Messages API, the following parameters are posted/returned in JSON.
If at least one attachment is written, then the resulting body will have a multipart/form-data content type, otherwise it will have an application/x-www-form-urlencoded content type.
Parameter | Type | Description |
---|---|---|
domain | String | The domain name this message was received from. |
recipient | string | The recipient of the message as reported by MAIL TO during SMTP chat |
sender | string | The sender of the message as reported by MAIL FROM during SMTP chat. (This value may differ from the MIME header) |
from | string | The sender of the message as reported by from message header, for example "Bob Lee <blee@mailgun.net>". |
subject | string | The subject string |
body-plain | string | The text version of the email. This field is always present. If the incoming message only has HTML body, Mailgun will create a text representation for you. |
stripped-text | string | The text version of the message without the quoted parts and signature block (if found) |
stripped-signature | string | The signature block stripped from the plain text message (if found) |
body-html | string | The HTML version of the message, if message was multipart. Note that all parts of the message will be posted, not just text/html. For instance, if a message arrives with "foo" part it will be posted as "body-foo" |
stripped-html | string | The HTML version of the message, without the quoted parts |
attachments | string | The string that contains a JSON list of metadata objects, one for each attachment. |
message-url | string | A URL that you can use to get and/or delete the message. Only present in the payload posted to the notification URL |
timestamp | int | The number of seconds passed since January 1, 1970 (See Securing Webhooks) |
token | string | A randomly generated string with a length of 50 (See Securing Webhooks) |
signature | string | A string with hexadecimal digits generated by HMAC algorithm (See securing webhooks). |
message-headers | string | A list of MIME headers dumped to a JSON string (The o_rder of headers is preserved)_ |
Content-id-map | string |
Alternatively, you can choose the following parameters when the Accept header is set to message/rfc2822
Parameter | type | Description |
---|---|---|
recipient | string | The recipient of the message |
sender | string | The sender of the message |
from | string | The sender of the message as reported by the from message header. Example: <bob@example.com>" |
subject | string | The subject string |
`Body-mime | string | The Full MIME envelope. You will need a MIME parsing library to process this data |
Spam Filter
A spam filter is necessary when receiving email. Mailgun is powered by an army of SpamAssassin machines. Mailgun gives you three ways to configure spam filtering.
Click the Domains tab on the Control Panel and select from one of the following three options:
- Disabled (default)
- Delete Spam (spam is removed and you won't see it)
- Mark spam with MIME headers (You decide what to do with it)
If you choose to mark spam with MIME headers, Mailgun provides you with these four:
- X-Mailgun-Sflag - Inserted with the value
Yes
if the message was classified as spam. - X-Mailgun-Sscore - A 'spamicity' score that you can use to calibrate your own filter. Inserted for every message checked for spam. The score ranges from low negative digits (very unlikely to be spam) to 20 and occasionally higher (very likely to be spam).
- X-Mailgun-Dkim-Check-Result - If DKIM is used to sign an inbound message, Mailgun will attempt DKIM validation, the results will be stored in this header. Possible values are:
Pass
orFail
- X-Mailgun-Spf -Mailgun will perform an SPF validation, and results will be stored in this header. Possible values are:
Pass
,Neutral
,Fail
orSoftFail
.