User guide

API reference


Sample inbound workflow

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 webhook URL. The basic workflow for this feature will look something like this:

  1. A user posts a comment on your site or app.
  2. An email notification with the comment included is sent to anyone subscribed to that item.
  3. The users who received the comment notification can click reply in their email client, replying through a unique email address that forwards to Postmark Inbound.
  4. The email is parsed by Postmark Inbound into a JSON document.
  5. The JSON document is sent to a webhook URL for your web application.
  6. The email reply shows up as a comment inside the app, as a reply to the original message.

Steps #

1. Setup a forwarding address

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 webhook URL.

There are two options to set up an inbound address for your domain: Postmark’s Inbound Domain Forwarding or if you do not have access to edit your DNS records, you can read our help article to learn how to configure a custom forwarding email address from your Gmail/Google Apps account.

2. Determine how you will identify unique replies

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. We also recommend that you store a relationship between the hash used and the original identifiers to enable quick lookups. We talk about this more here.

3. Processing the data in your application

When a user replies, the email contents and headers, along with other useful custom information, will be sent to your webhook. Now it is time to process the JSON data with that webhook.

When a hook returns a non-200 code, we will schedule the JSON post for a retry. A total of 10 retries will be made, with growing intervals from 1 minute to 6 hours. If all of the retries have failed, your Inbound page will show the message as Inbound Error.

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.