Monday, March 3, 2014

Sending and Receiving Email using Mandrill

This post will show you how your NodeJS app can send and receive emails using Mandrill. It will show you how to setup the emails you send so that when your users reply to those emails, your application can process those replies.

The trick to receive emails is to send the initial email with a unique reply-to email address. That way, when the user replies to the email, your app will use that unique email address to process the message.

For the examples in this post, the reply-to email address will look like reply-123@replies.sampleapp.com, where 123 is the unique id of some object in your app. We use reply- in the email address because that lets us setup a route in Mandrill that matches email addresses that starts with reply- followed by some id. The mandrill documentation tells you how to setup that kind of route, see section Adding Routes in Mandrill's Inbound Email Processing Overview.

Thus, when your app receives an email from reply-123@replies.sampleapp.com, your app will know that the contents of the email belong to object with id 123. And from there you will apply your specific business requirement.