Skip to content
Last updated

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.

ParameterTypeDescription
domainStringThe domain name this message was received from.
recipientstringThe recipient of the message as reported by MAIL TO during SMTP chat
senderstringThe sender of the message as reported by MAIL FROM during SMTP chat. (This value may differ from the MIME header)
fromstringThe sender of the message as reported by from message header, for example "Bob Lee <blee@mailgun.net>".
subjectstringThe subject string
body-plainstringThe 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-textstringThe text version of the message without the quoted parts and signature block (if found)
stripped-signaturestringThe signature block stripped from the plain text message (if found)
body-htmlstringThe 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-htmlstringThe HTML version of the message, without the quoted parts
attachmentsstringThe string that contains a JSON list of metadata objects, one for each attachment.
message-urlstringA URL that you can use to get and/or delete the message. Only present in the payload posted to the notification URL
timestampintThe number of seconds passed since January 1, 1970 (See Securing Webhooks)
tokenstringA randomly generated string with a length of 50 (See Securing Webhooks)
signaturestringA string with hexadecimal digits generated by HMAC algorithm (See securing webhooks).
message-headersstringA list of MIME headers dumped to a JSON string (The o_rder of headers is preserved)_
Content-id-mapstring

Alternatively, you can choose the following parameters when the Accept header is set to message/rfc2822

ParametertypeDescription
recipientstringThe recipient of the message
senderstringThe sender of the message
fromstringThe sender of the message as reported by the from message header. Example: <bob@example.com>"
subjectstringThe subject string
`Body-mimestringThe 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 or Fail
  • X-Mailgun-Spf -Mailgun will perform an SPF validation, and results will be stored in this header. Possible values are: Pass, Neutral, Fail or SoftFail.