How to set up Inbound Emailing with Postmark’s Inbound Processing

If you want your users to be able to reply to transactional emails and get their replies into your platform (e.g. as a message, etc.) you can use Postmark’s Emailing API to set up inbound parse.

Before using Postmark, I tried Sendgrid’s inbound parse and researched a variety of options, but decided to go with Postmark due to great pricing, great documentation and a good parser engine that cuts old email threads automatically before posting the content to your app’s endpoint.

Here it goes:

1) Sign up for Postmark and setup a new server. Call it “inbound parser” or whatever you want to name it.

image

2) Create a new backend workflow in your app. This should be a public endpoint. Check the setting below. Call it whatever you want.

image

3) Go to Settings / API and copy your apps public endpoint link.

4) Go back to your workflow, click “Detect Data”

5) Go to your server’s settings page in Postmark and paste the public endpoint link into the webhook field. Click “Check” (make sure your app is waiting for the call aka the “Detecting Request Data” dialogue is open). Postmark will now do a test call to the public endpoint in your app. If it worked out, it will return with a status code of 200. Click “Save Changes”

6) Back in your app, you will now see the Request Data overview dialogue. Click “Save”. Awesome! You just setup inbound parse into your app.

image

7) You can now send emails to Postmark’s inbound email address to test your connection (find it on your servers settings page). Any email sent to this address will be posted to your endpoint. You should set up inbound domain forwarding in Postmark. I won’t explain this, as it’s documented very well within Postmark.

8) Now you can do all sorts of fun stuff in the app with the data from Postmark, e.g. create messages, etc.

image

Things to consider:

A) I recommend to set up an “intermediary” data type, that saves the most important info from the call your endpoint receives. Different email engines send data in different formats to Postmarks, so e.g. “Stripped Text Reply” might not always work. You could call this “Parse_Data” and save things like the inbound emails from, to, html reply body, stripped text reply body, text body, etc. This is important to not loose data, when something goes wrong.

B) It’s possible to take attachments from incoming emails and save them in the app. I will explain how to do this below.

C) To make sure incoming emails are routed to the right user, conversation, whatever you want to use the data for, you should assign individual keys to each user, message stream, etc. in your app and set them as the reply_to address when you send outbound emails for conversational transactional emails.
We solved by setting outbound email reply_to email addresses as INDIVIDUALKEYUSER12DIGITS_INDIVIDUALKEYANOTHERTHING12DIGITS@yourappdomain.com (e.g. asdf1234qwer_iopu7890hjkl@yourappdomain.com).
When a user replies to an email, the app will cut the reply_to information from the Postmark call using find&replace and truncated_to and do a search for the right user and message stream.

Bonus: create files from inbound email attachments

1) Create a new datatype. I call this “parsefile”. “message” is the message in my database (another datatype) that I want to attach the files to.

2) Create a new backend workflow. I call this “create_attachments”

3) This is the workflow (in the right order) that I set up to create attachments. You will need the plugin “EZ Uploader” to decode the Base64 attachments.

Step 1) Create a new “parsefiles”

Step 2) Decode the base64 string attachment using the EZ Uploader plugin

Step 3) Use the newly created file and attach it to whatever you want (e.g. a message). The file can be accessed like this
image

Step 4) Add a step in your inbound parse workflow where you schedule this backend workflow on the list “Request Data’s attachments” (which is a basically a list base64 encoded strings which are your attachments)

Feel free to ask questions! Hope this helps

31 Likes

I keep getting a 404 error from Postmark, post the initial test, it’s driving me crazy. Have retraced my footsteps many times. Any ideas would be massively appreciated? Thank you!

Did you initialize the endpoint? The URL you put into postmarks field here, is not the initialisation webhook url. You need to click on “detect data” in this popup first and then copy and paste the URL given there into postmark. Afterwards it should work and then you can replace that URL with your actual endpoint url.

Edit: just realised I skipped that step in the initial explanation. Sorry for any grey hair this may have caused!

1 Like

You sir are a gent, thank you very much! Have a great festive period!

Hello @maru !

This is a great post ! Thanks a lot ! It works like a charm !

But I have a question : How do you deal with multiples attachments ?

Do you have any idea why I have error code 401?

Thanks

Can you specify where and under what circumstances you get a 401 error?

Sending multiple attachments should also work fine, where are you stuck or what error are you getting?
Sorry for the late reply btw

After pressing the detect button on bubble, when I check the address at postmark… As in the image attached…

is the initialize popup open in the bubble editor? If it is not open, bubble is not waiting for data on this endpoint and will return a 401. After the endpoint has been initialized, you have to switch the initializition-endpoint URI with the URI that should be used for production. Hope that solves it!

Thank you very much for your patience.
It is open and I have switched the URL for the one appearing on the popup… same message :frowning:

I’m afraid, that I cannot replicate the issue. Everythings works fine for me, when I follow the above steps.

Make sure there are no typos in the URI, the backend workflow is exposed as public workflow and the “Detect Request Data” popup is open and listening for data posted to this endpoint. It’s most likely an authentication issue (hence the 401) - do you have workflow APIs enabled under settings? Maybe try to set the workflow settings to “can be run without authentication”.

Hello Maru,

thanks, I solved the problem :slight_smile:

Best regards,

Jeremy

Thanks Maru!
I am not a coder and have only been using bubble for 3 weeks but worked out how to send and receive an email thanks to your set up. The last bit I am stuck with is “truncating” the incoming “to” field so that it reflects the ID of a thing (in my case a “message subject”). Are you able to share an example of how you stripped out the value using “find and replace”?
Thanks in advance!

Update… I solved it!
My error was I was trying to match an ID of a thing. Instead I created a new field which generates a unique email address and matched incoming mail to that. Here is an explanation of my set up:

  1. Thing called “Message Subject”
  2. Thing called “Message” (A Message Subject can have many messages)
  3. When a Message Subject is first generated, it has a field called “Email Subject” which populates with the first message ID created with it + @[domain]
  4. When a new message is sent to recipients, reply to field is message subject → email subject field
  5. When an inbound message is parsed, the reply to field is matched to the message subject → email subject field to attach it the message that is generated.

Thanks again Maru for taking the time to create these instructions

1 Like

@maru this is so helpful, thank you!!!

I’m running into an issue where I can access base64 data for PNG files, but not JPG/JPEG files. Any idea what might be happening? I don’t see the Content field in the response for JPG as an example

Hi Maru, Thank you for this detailed post. However I am facing an issue that I can’t seem to resolve. When I send an inbound email it gives me an error 404 as follows:

My Webhook has been attached successfully :

Response on my bubble app is also being received :

Can you kindly guide me as to what might be causing this issue?

1 Like

@maru I come across the same issue :frowning_face:
The webhook url (created at the detect data) is not found when I get another inbound email.
Your help would be much appreciated here.
Thanks in advance

You have to change the endpoint URL in postmark to the production endpoint URL (e.g. circular-monster.com/version-live/api/1.1/wf/parse_emails)

Hope that solves it.

Another Update that I hope will save some people some time… When you “Test” the endpoint from postmark - attachment files content is called “data”. But in actual use the attachment files content is called “content”. Attachment files will not work if you use “data” as the definition. To avoid this, when testing to initialise, do not hit “test” in postmark. Instead, send an actual email with an attachment to the incoming server so that it processes it and calls the attachment “content”. You can then use the correct definition “content” in your workflow to process attachments. Postmark support said it is on their to do list to fix this error so that “test” definitions are correct.

1 Like