Mandrill Webhooks & Inbound Email Processing
Mandrill Webhooks provides the respective users with the option to keep tabs on events related to emails. Therefore, you can rightly say that Mandrill supervises task like outbound message notifications and delivering inbound email processed via Mandrill.
With this blog I will try to explain how to add your comment by replying to the notification email of a post.
Inbound processing is responsible for inbound email receptions (like to email@example.com) via Mandrill. Mandrill follows a cyclical process of accepting the messages, parsing them, identify attachments and contents as well as categorizing them.
Set up your domain for Inbound email:
Initially, you need to determine the domain (s) to be used for inbound emails and make essential changes to the domain DNS setting so that the emails get forwarded to the Mandrill.
Steps to set up inbound email domains:
- Login to your Mandrill account and choose the path: Inbound > Domains.
- Fill in the domain where you want to receive mail and click add domain.
- Once the domain is added, all the emails sent to it will be rerouted to Mandill instead of conventional email inboxes. It is always ideal to use a unique subdomain like “inbound.yourdomain.com”.
- Click on the DNS Setting tab for your domain to view the information that you need to connect to MX record interface of your DNS provider. This will alert the service provider you have chosen Mandrill to handle the respective email transactions.
- To process your mail through Mandrill, configure your domain to route incoming messages to the Mandrill email servers. To do that, go to your domain DNS settings and add the above MX records.
- Once MX records are added, click the Test button and mandrill verifies whether the setting are correct.
Once the MX record verification is complete, you have the option of defining routes for your domain. Use the Route button to send messages from your domain to any URLs based on the email address.
For example, you might want to go to. Fill the email address as firstname.lastname@example.org and the Post to URL as http://yourdomain.com/post-as-comment.
When a new post/blog/feed is added in your web page. Send your users a notification saying “New post added …. Please reply to this mail to add your comment on this post”. Set the reply-to email header as email@example.com. Mandrill now accept all the messages to firstname.lastname@example.org, parse them to break out attachments and content, then POST them into the webhook url http://yourdomain.com/post-as-comment. You can process the parsed email data posted into your page and add it as comment to the appropriate post. Use any hidden data or specific route format to identify the appropriate post, like post-id or something.
Another example, All messages to inboxes ending with “-email@example.com” to go to http://yourdomain.com/replies. In this case, your route would be “*-firstname.lastname@example.org”.
Inbound emails are processed with respect to the routes set up earlier and the messages/notifications respective to the routes are forwarded to designated URL (s) as a webhook. Here, the webhooks, follow a similar format to that of the other webhooks of Mandrill.
The webhook request is ideally a standard POST request with a single parameter – mandrill_events. This parameter will contain a JSON-encoded array of the messages that match the webhook information.
Improve your users experience with such a nice feature.