Parse inbound email

What is inbound parsing?

Receiving email is harder for developers than sending it, because there’s no easy way to retrieve the actual message from unstructured incoming emails. Developers commonly describe processing incoming emails as “a real pain” or “a headache”.

This leads to poor user experiences when emails meant to be replied to (for example, messages from buyers on a marketplace) come from a no-reply address and feature a “Reply” button that pushes the user into a cumbersome reply flow on an app or website.

Inbound parsing at Brevo

Brevo’s parsing technology comes from the acquisition of MailClark, whose technology has converted millions of unstructured emails into formatted chat messages since 2015. Using algorithms and machine learning, the actual message and signatures are extracted from raw emails and converted into Markdown.

Emails are received and processed on our end, then delivered to you as a structured JSON payload (described in the next chapter) via a webhook.

Setting up your Inbound parsing webhook

Preparing your domain

For the setup, determine two things first:

  • The receiving domain (or subdomain) for the emails to be parsed. It must differ from the domain used for sending email. We recommend creating a subdomain such as reply.yourdomain.com.
  • The webhook URL that Brevo will call to send events when an inbound email has been parsed.

Make sure your domain is verified with Brevo.

Next, delegate the receiving domain to Brevo. Update your DNS configuration for reply.yourdomain.com so emails sent to this domain are received on Brevo servers. Add the following two records:

Record domainRecord TypeRecord PriorityRecord value
reply.yourdomain.comMX10inbound1.sendinblue.com.
reply.yourdomain.comMX20inbound2.sendinblue.com.

DNS changes can take several hours to propagate, so apply this configuration as early as possible.

Creating the webhook

The same endpoints used to create, get, update and delete webhooks for Marketing and Transactional events also manage Inbound parsing webhooks.

The differences compared to events-related webhooks, shown in the sample POST request below, are:

  • Use inbound for type and inboundEmailProcessed for events
  • Specify your receiving domain
POST https://api.brevo.com/v3/webhooks
1//example
2{
3 "type": "inbound",
4 "events": ["inboundEmailProcessed"],
5 "url":"https://hook.znapi.cc/ix0v9y", //Your ingress
6 "domain": "reply.yourdomain.com",
7 "description":"Webhook to receive replies"
8}

With this configuration, any email sent to *@reply.yourdomain.com is received by our API, parsed, converted to JSON, and POSTed to http://example.domain.com/1brxxxxxx5p1.

Parsed email payload

The JSON body contains a top-level items array listing the received emails. Each email has the following properties:

Inbound email propertyData typeDescription
Uuidstring[]A list of recipients UUID (can be used with the Public API)
MessageIdstringThe Message-ID header of the inbound email.
InReplyTo?stringMessage-ID of the original email this one replies to (if applicable)
FromMailboxAuthor of the email (the person who sent it)
ToMailbox[]The primary recipients of the email
RecipientsMailbox[]RCPT TO recipients
CcMailbox[]The secondary/informational recipients of the email
ReplyTo?MailboxWhere replies to this email should be sent (if different than the author in the From property)
SentAtDatestringThe Date header of the inbound email (format should be RFC822)
SubjectstringThe Subject header of the inbound email
RawHtmlBody?stringThe HTML version of the inbound email
RawTextBody?stringThe text version of the inbound email
ExtractedMarkdownMessagestringThe markdown version that was extracted by the Brevo parsing (without the signature)
ExtractedMarkdownSignature?stringThe signature that was recognized by the Brevo parsing
Spam.ScorefloatSpam is an object with a Score property. It is calculating using rspamd (it’s not extracted from the headers).
AttachmentsAttachment[]The list of attachments included in the inbound email.
Headersarray of string or []stringThe complete headers list of the inbound email.
Headers that appear once will be sent as a string. Headers that appear multiple times will be sent as an array of string[]

The Mailbox object

Mailbox propertyData typeDescription
AddressstringEmail address of the person
Name?stringName of the person

The Attachment object

Use the DownloadToken(see below) to retrieve attachments using this endpoint.

Attachment propertyData typeDescription
NamestringName of the attachment
ContentTypestringContent-Type of the attachment
ContentLengthintegerEstimated size of the attachment
ContentIDstringID used to reference the content in the HTML version (if applicable, e.g. inline images)
DownloadTokenstringToken needed to fetch the attachment

Sample payload

Webhook JSON payload
1{
2 "items": [
3 {
4 "Uuid": [
5 "1a825d56-029b-4a41-b8e4-61670463431b"
6 ],
7 "MessageId": "<CAN0zNmMsj_xOx8hCREv3rbovcYE3m5rZh8eRe+QSKC0yff_W6A@mail.gmail.com>",
8 "InReplyTo": "<e6df8cf2-cfb2-2cb6-320f-d9cba05a3001@clubble.me>",
9 "From": {
10 "Name": "Antoine Lefeuvre",
11 "Address": "antoine@mailclark.ai"
12 },
13 "To": [
14 {
15 "Name": "Terry Estill",
16 "Address": "test@clubble.me"
17 }
18 ],
19 "Recipients": [
20 "test-2023-08-02@sib-inbound.esperat.fr"
21 ],
22 "Cc": [],
23 "ReplyTo": null,
24 "SentAtDate": "Tue, 1 Sep 2020 09:53:21 +0200",
25 "Subject": "Re: Summer brochure 2021",
26 "RawHtmlBody": "<div dir=\"ltr\">Hi Terry,<br />Nice to hear from you, I hope you&#39;re well.<br />Sure, our summer brochure is already out \ud83d\ude0e! I&#39;ve attached it <b>together with our winter brochure\u00a0<\/b>\u26c4.<br /><br />I&#39;ve heard you&#39;re a massive fan of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Rubber_duck_debugging\">rubber ducks<\/a>, so I wanted to share with you this picture I took this summer. <i>Amazing, eh?<\/i><div><div><img src=\"cid:ii_kejngtlh0\" alt=\"duck1.png\" width=\"294\" height=\"196\" style=\"margin-right: 0px;\"><br /><\/div><br />Any questions (about the brochures, not the ducks \ud83d\ude1c), I&#39;d\u00a0be happy to help.<br /><br />Speak soon,\u00a0\u00a0<br clear=\"all\"><div><div dir=\"ltr\" class=\"gmail_signature\" data-smartmail=\"gmail_signature\"><div dir=\"ltr\"><div><div dir=\"ltr\"><div><div dir=\"ltr\"><b>Antoine Lefeuvre<\/b><br />Co-founder &amp; Product Manager at <a href=\"https:\/\/mailclark.ai\" target=\"_blank\">MailClark<\/a><br /><a href=\"mailto:antoine@mailclark.ai\" target=\"_blank\">antoine@mailclark.ai<\/a><br /><a href=\"https:\/\/twitter.com\/jiraisurfer\" target=\"_blank\">Twitter<\/a> <a href=\"https:\/\/www.linkedin.com\/in\/lefeuvre\" target=\"_blank\">LinkedIn<\/a><br /><i>Sent with MailClark<\/i><br /><\/div><\/div><\/div><\/div><\/div><\/div><\/div><br /><\/div><\/div><br /><div class=\"gmail_quote\"><div dir=\"ltr\" class=\"gmail_attr\">On Tue, 1 Sep 2020 at 09:43, Terry Estill &lt;<a href=\"mailto:test@clubble.me\">test@clubble.me<\/a>&gt; wrote:<br /><\/div><blockquote class=\"gmail_quote\" style=\"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex\">\n \n \n \n <div bgcolor=\"#FFFFFF\">\n <p>Hi there, I hope things with you are good.<br />\n <br />\n I was wondering whether your brochure for the summer next year was\n already available. I&#39;m willing to start planning asap.<br />\n <br />\n Best,<br />\n <\/p>\n <div>-- <br />\n <strong>Terry Estill<\/strong>\u2014Cofounder &amp; CEO<br />\n <em>The Wheat Assembly - Le Club Bl\u00e9<\/em><br />\n <a href=\"mailto:test@clubble.me\" target=\"_blank\">test@clubble.me<\/a><br />\n <a href=\"http:\/\/www.clubble.me\" target=\"_blank\">www.clubble.me<\/a><\/div>\n <\/div>\n\n<\/blockquote><\/div>\n",
27 "RawTextBody": "Hi Terry,\nNice to hear from you, I hope you're well.\nSure, our summer brochure is already out \ud83d\ude0e! I've attached it *together\nwith our winter brochure *\u26c4.\n\nI've heard you're a massive fan of rubber ducks\n<https:\/\/en.wikipedia.org\/wiki\/Rubber_duck_debugging>, so I wanted to share\nwith you this picture I took this summer. *Amazing, eh?*\n[image: duck1.png]\n\nAny questions (about the brochures, not the ducks \ud83d\ude1c), I'd be happy to help.\n\nSpeak soon,\n*Antoine Lefeuvre*\nCo-founder & Product Manager at MailClark <https:\/\/mailclark.ai>\nantoine@mailclark.ai\nTwitter <https:\/\/twitter.com\/jiraisurfer> LinkedIn\n<https:\/\/www.linkedin.com\/in\/lefeuvre>\n*Sent with MailClark*\n\n\nOn Tue, 1 Sep 2020 at 09:43, Terry Estill <test@clubble.me> wrote:\n\n> Hi there, I hope things with you are good.\n>\n> I was wondering whether your brochure for the summer next year was already\n> available. I'm willing to start planning asap.\n>\n> Best,\n> --\n> *Terry Estill*\u2014Cofounder & CEO\n> *The Wheat Assembly - Le Club Bl\u00e9*\n> test@clubble.me\n> www.clubble.me\n>\n",
28 "ExtractedMarkdownMessage": "Hi Terry, \nNice to hear from you, I hope you're well. \nSure, our summer brochure is already out \ud83d\ude0e! I've attached it **together with our winter brochure**\u00a0\u26c4. \n\nI've heard you're a massive fan of [rubber ducks](https:\/\/en.wikipedia.org\/wiki\/Rubber_duck_debugging), so I wanted to share with you this picture I took this summer. *Amazing, eh?* \n\n[duck1.png](ii_kejngtlh0) \n\nAny questions (about the brochures, not the ducks \ud83d\ude1c), I'd\u00a0be happy to help. \n\nSpeak soon,\u00a0\u00a0 \n",
29 "ExtractedMarkdownSignature": "**Antoine Lefeuvre** \nCo-founder &amp; Product Manager at [MailClark](https:\/\/mailclark.ai) \n[antoine@mailclark.ai](mailto:antoine@mailclark.ai) \n[Twitter](https:\/\/twitter.com\/jiraisurfer) [LinkedIn](https:\/\/www.linkedin.com\/in\/lefeuvre) \n*Sent with MailClark*",
30 "SpamScore": 3.3,
31 "Attachments": [
32 {
33 "Name": "duck1.png",
34 "ContentType": "image\/png",
35 "ContentLength": 330518,
36 "ContentID": "ii_kejngtlh0",
37 "DownloadToken": "abc"
38 },
39 {
40 "Name": "summer2021.pdf",
41 "ContentType": "application\/pdf",
42 "ContentLength": 168910,
43 "ContentID": "f_kejnjyug1",
44 "DownloadToken": "def"
45 },
46 {
47 "Name": "winter2020-2021.pdf",
48 "ContentType": "application\/pdf",
49 "ContentLength": 113007,
50 "ContentID": "f_kejnjyv02",
51 "DownloadToken": "xyz"
52 }
53 ],
54 "Headers": {
55 "Return-Path": "<antoine@mailclark.ai>",
56 "Delivered-To": "test@clubble.me",
57 "Received": [
58 "from spool.mail.gandi.net (spool5.mail.gandi.net [217.70.178.214]) by nmboxes20.sd4.0x35.net (Postfix) with ESMTP id 7115220256 for <test@clubble.me>; Tue, 1 Sep 2020 07:53:43 +0000 (UTC)",
59 "from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by spool.mail.gandi.net (Postfix) with ESMTPS id 4B618D80F65 for <test@clubble.me>; Tue, 1 Sep 2020 07:53:41 +0000 (UTC)",
60 "from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by mx.zohomail.com with SMTPS id 1598946814954566.0226921077056; Tue, 1 Sep 2020 00:53:34 -0700 (PDT)",
61 "by mail-ot1-f42.google.com with SMTP id a65so390247otc.8 for <test@clubble.me>; Tue, 01 Sep 2020 00:53:34 -0700 (PDT)"
62 ],
63 "ARC-Seal": "i=1; a=rsa-sha256; t=1598946818; cv=none; d=zohomail.com; s=zohoarc; b=A7jKTJCD9ieoEKAPtoZpyxtuJQp8ek0cIqCbf2HUvJkkVYmXIhI6jiLtYaR6Sm0Et5r\/E5vFPowt6RjFtWaDaz7UoW9CIiePJkEkGHgHhQ343s2IUWlADGGsCEPskwCvlJvn3tVSiABgQLIsf6FaqfkDZEOYtejRC786Jlb8eT8=",
64 "ARC-Message-Signature": "i=1; a=rsa-sha256; c=relaxed\/relaxed; d=zohomail.com; s=zohoarc; t=1598946818; h=Content-Type:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=CgBV\/y5azQ9uDe+uFDrdGKiTQx6DwkxdL1XwOip9ZEU=; b=XuCp2CYwXDNo5dDdBML4beYI+IUT4+81Pr78RmDWpoaQfumm22YX3TF2tjITVtYnqmUDbLUoR4bBmPgrPIUWxsOc+omLlpg2FyjXO8Xyw\/MCazKZhrUuHaIvsMbV\/QOZLavGITgKtTVw8iMg2M1hVz8Ay8VKqG\/oFkbJxbzdZh8=",
65 "ARC-Authentication-Results": "i=1; mx.zohomail.com; dkim=pass header.i=mailclark.ai; spf=pass smtp.mailfrom=antoine@mailclark.ai; dmarc=pass header.from=<antoine@mailclark.ai> header.from=<antoine@mailclark.ai>",
66 "DKIM-Signature": "v=1; a=rsa-sha256; q=dns\/txt; c=relaxed\/relaxed; t=1598946818; s=zoho; d=mailclark.ai; i=antoine@mailclark.ai; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Content-Type; bh=CgBV\/y5azQ9uDe+uFDrdGKiTQx6DwkxdL1XwOip9ZEU=; b=i4YJj1RFryuXbHDh8E9oKZv3+e6Kzat5oAxwuLZV4w\/t2b1rTBP\/qGMArXvuSRAz lNZvfJj4Kf7VD7nQMRrm8EdXGyuWPvVfjBU9PQjFs\/6GkANzLJW5PGGXZrlDXFIpiHH e5tmnYmFSfplAMsyZokpm5oDjT2whR34YZCGcUOg=",
67 "X-Gm-Message-State": "AOAM530ChFmHzQDIPhTYzy4S5fs4ciUbgttaJYjt92mK62LXV52RGa7h zEkGPJ3KsDnCA7b9DrENpVFt\/zojNvW+Ha4nVbU=",
68 "X-Google-Smtp-Source": "ABdhPJxFuLbNc8G\/rGIwkCPsDITPakKQW3VZe3+48by7auFyBNSjppLNydYymK21mcORQgOG5fYNeJkXu3+EPkerxj0=",
69 "X-Received": "by 2002:a9d:58c8:: with SMTP id s8mr541588oth.292.1598946813444; Tue, 01 Sep 2020 00:53:33 -0700 (PDT)",
70 "MIME-Version": "1.0",
71 "References": "<e6df8cf2-cfb2-2cb6-320f-d9cba05a3001@clubble.me>",
72 "In-Reply-To": "<e6df8cf2-cfb2-2cb6-320f-d9cba05a3001@clubble.me>",
73 "From": "Antoine Lefeuvre <antoine@mailclark.ai>",
74 "Date": "Tue, 1 Sep 2020 09:53:21 +0200",
75 "X-Gmail-Original-Message-ID": "<CAN0zNmMsj_xOx8hCREv3rbovcYE3m5rZh8eRe+QSKC0yff_W6A@mail.gmail.com>",
76 "Message-ID": "<CAN0zNmMsj_xOx8hCREv3rbovcYE3m5rZh8eRe+QSKC0yff_W6A@mail.gmail.com>",
77 "Subject": "Re: Summer brochure 2021",
78 "To": "Terry Estill <test@clubble.me>",
79 "Content-Type": "multipart\/mixed",
80 "X-Zoho-Virus-Status": "1",
81 "X-ZohoMailClient": "External",
82 "X-GND-Status": "LEGIT",
83 "Received-SPF": "pass (spool5: domain of mailclark.ai designates 136.143.188.51 as permitted sender) client-ip=136.143.188.51; envelope-from=antoine@mailclark.ai; helo=sender4-of-o51.zoho.com;"
84 }
85 }
86 ]
87}

Logs and inbound email parsing activity

Two endpoints let you access logs and monitor inbound parsing activity:

  1. List and filter received emails by date and/or sender via your Inbound parsing webhook.

  2. Get full details for a particular email received via your Inbound parsing webhook.

Ongoing improvement

Given the diversity of email apps, languages, and formatting, a 100% success rate on inbound parsing is impossible. We continuously improve the parsing engine, and you can contribute by reporting parsing failures.

Depending on the cause of the parsing failure, we may or may not be able to correct a given error. For example, if quoted replies aren’t stripped because an email app uses an unusual format, we can integrate that format into our algorithm and fix the issue once the parsing engine is updated. On the other hand, if a segment is wrongly identified as a signature, we may not be able to correct that specific case because signature detection uses machine learning. Your failure reports still help our data scientists fine-tune what they “teach” the model.

Send your failure report to contact at brevo.com with the following details:

  • Subject line: Inbound Parsing API Failure
  • JSON payload (or relevant excerpt of the payload + UUID)
  • Reason for failure:
    • Quoted replies not removed from ExtractedMarkdownMessage
    • Signature not removed ExtractedMarkdownMessage
    • Truncated ExtractedMarkdownMessage
    • Truncated or empty ExtractedMarkdownSignature
    • Message content wrongly detected as ExtractedMarkdownSignature