Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Configure the inbound parse webhook


Twilio SendGrid can help process email using the Inbound Parse webhook. The Inbound Parse webhook parses the contents and attachments for incoming email to a email server, then send that data to a URL of your choice. You can choose how your application handles this parsed data.

For examples of the Inbound Parse webhook, see the blog posts Parse API: Oh, What You Can Do!(link takes you to an external page) and Microservice for Handling SendGrid Inbound Parse(link takes you to an external page).

(information)

Info

To review pre-made integrations for the Twilio SendGrid Inbound Parse webhook, see the Library Index.


Prerequisites

prerequisites page anchor

Before you configure the Inbound Parse webhook, complete the following tasks:

  • Create and configure MX records.
  • Choose the hostname or receiving domain that receives the emails to parse.
  • Define the URL that receives your parsed emails.

  1. Go to the MX Records page on your domain provider website.
    If you don't know who hosts your domain, contact your website administrator or networking team.
  2. Create a new MX record.
  3. Set the subdomain or hostname to the one that processes incoming email followed by a period (.).
    • This hostname should serve no other purpose other than parsing your incoming email.
    • Never change the MX record for your domain. If you do, your domain stops receiving email.
  4. Set the priority to 10.
  5. Set the mail server address to mx.sendgrid.net. If your provider offers field for priority, type 10 before the mail server address. 10 mx.sendgrid.net.
  6. Leave the Time to Live or TTL value unchanged.
  7. Click Save or Add depending on your domain provider user interface.

Example MX record

example-mx-record page anchor
1
HOST TYPE TTL SERVER
2
------ ---- ---- ----------------
3
parse. MX 3600 mx.sendgrid.net.

Set the email server and webhook URL

set-the-email-server-and-webhook-url page anchor

The inbound parse requires two parameters:

  • Receiving domain: The domain that encompasses the email servers that receive the email messages you want to parse
  • Destination URL: The URL at which your Inbound Parse webhook is hosted

To configure the inbound parse webhook:

  1. Log in to the Twilio SendGrid Console(link takes you to an external page).

  2. Go to Settings > Inbound Parse. The Inbound Parse page appears.

  3. Click Add Host & URL. The Add Host & URL panel appears.

  4. In the Receiving domain fields, provide the following:

    • Type the hostname or subdomain for your domain in the box, if needed.
    • Select the domain from the Domain dropdown menu.

    Twilio parses all email messages sent to the receiving domain.

    If you set your receiving domain to the same value as your authenticated domain, turn off Automatic Security on the authenticated domain. Otherwise, messages sent to the receiving domain bounce in an infinite loop between the servers set as the canonical domain name (CNAME) and the mail exchanger (MX) records.

  5. In the Destination URL, type the webhook URL that should receive the parsed email data. This URL must be accessible from the internet.

  6. In the Additional Options section, select one or both of the options.

    • To have Inbound Parse check incoming email 2.5 MB or smaller for spam, select Check incoming emails for spam. Checking this box also includes the spam report and spam score in the payload. In general, spam email messages don't exceed 2.5 MB. The Twilio SendGrid-generated report marks those messages as not spam.
    • To URL encode both the email messages and their attachments, select POST the raw, full MIME message.
      If you don't select POST the raw, full MIME message, Twilio SendGrid URL encodes the message but not their attachments. If your code only reads URL-encoded content, it can drop attachments.
  7. Click Add.


To test the webhook, send an email from your email account to an email address on your receiving domain, like example@example.com.

The local-part of this email address, anything before @, can be any single word or combination of words with three exceptions: abuse, postmaster, and unsubscribe. This means you can't use abuse@subdomain.example.com, postmaster@subdomain.example.com, and unsubscribe@subdomain.example.com.


Examples of the payloads and their parameters

examples-of-the-payloads-and-their-parameters page anchor
Default Data FormatRaw Data Format
ParameterDescription
headersThe raw headers of the email.
dkimThe verification results of any DKIM and domain keys signatures in the message.
content-idsThe identifiers of the attachments included in the email message.
toA JSON object containing the email address of the recipient extracted from the message headers.
textThe text-formatted form of the email message body.
htmlThe HTML-formatted form of the email message body, if provided.
fromThe email sender extracted from the message headers.
sender_ipThe IP address from which the email message was sent.
spam_reportThe content of the report SpamAssassin(link takes you to an external page) generates.
envelopeA JSON object that represents the SMTP envelope.
envelope.fromThe return address for the message.
envelope.toA single-element array containing the address of the recipient of the received email message
attachmentsThe number of attachments included in email message.
subjectThe subject line of the email message.
spam_scoreThe SpamAssassin rating that determines if it considers this message spam.
attachment-infoA JSON object that contain one object for each attachment.
attachment-info.attachment{X}Each attachment key points to a JSON object for each attachment. X ranges from 0 to the total number of attachments.
attachment-info.attachment{X}.filenameThe name of the file if it was provided.
attachment-info.attachment{X}.typeThe media type(link takes you to an external page) of the file.
attachment-info.attachment{X}.content-idA unique identifier assigned to the file.
charsetsA JSON object that contains the character sets(link takes you to an external page) of the values extracted from the message.
SPFThe results of the Sender Policy Framework verification of the message sender and receiving IP address.

Statistics

statistics page anchor

Twilio SendGrid provides statistics(link takes you to an external page) of how many emails it parses over time. To specify what the graph displays, adjust the statistics filters.

To learn more, see Parse Webhook Stats.


  • Parse API: Manage Inbound Parse Webhook settings using the Parse API (Web API v3).
  • Parse Settings Subuser: Get current Parse settings and create, edit, and delete entries using the Subuser API (Web API v2).
  • Reseller API Parse Settings: Get current Parse settings and create, edit, and delete entries using the Reseller API (Web API v2).
  • Reseller Customer Subuser Parse Settings: Get current Parse settings and create, edit, and delete entries using the Reseller Customer Subuser API (Web API v2).