To bring all of this together, let's go through a real world example of processing an email from a user using Postmark Inbound. We'll use one of the most common scenarios, which is processing email replies to comment notifications sent from your application. Instead of forcing the users to login, they can simply reply to the email you sent them, and Postmark Inbound helps you post that reply into your app as a reply to the original message that was sent.
We will assume you already setup an Inbound server in Postmark, retrieved your unique email address, and set your hook URL. The basic workflow for this feature will look something like this:
In order to make this work, you will have to go through a few steps.
Your inbound mailbox will look something like abc123@inbound.postmarkapp.com. Since you want people to send emails to this address, it makes sense to carry your brand and domain and have the inbox name reflect the action they are taking. The easiest way to accomplish this is to forward an email to your inbound address. For instance, you can forward any emails sent to reply@yourdomain.com over to abc123@inbound.postmarkapp.com. This allows your users to reply or send emails to your own custom email address, and all information will be forwarded and captured by Postmark, parsed, and sent to your web hook url.
An easy way to forward emails is through Google Apps. Follow this help article to set that up.
In order to associate an email reply with the correct specific user and comment in your application, you will need a way to identify the reply and store it with the correct association in your application. For instance, if a user replies to a comment notification you might need to know the userID and threadID they are replying to. This is done by using the + sign to split the reply-to address and following it with any important information that needs to be captured.
Here is what the headers might look like in your comment notification:
From: reply@yourapp.com
Reply-to: reply+userIDthreadID@yourapp.com
To: youruser@domain.com
When someone replies to this email, Postmark will be able to parse the information after the + sign into the MailboxHash field of the JSON document, allowing you to easily associate the reply with the correct user and thread in your application.
"MailboxHash": "userIDthreadID"
Rather than leaving this information in plaintext, we recommend using SHA1 or MD5 to hash the information after the + sign. Even using a hash, we do not recommend using anything sensitive in the mailbox hash.
When a user replies, the email contents and headers, along with other useful custom information, will be sent to your web hook. Now it is time to process the JSON data with that webhook.
It will be up to you to choose how you process the data, since it depends heavily on the use case, programming language, and environment. We’ve collected some code examples to help you get started.