Sending emails from rails is an easy process. But sometimes we need to reply to the email itself that was sent by the app.
Postmark is the easiest and most reliable way to be sure your important transactional emails get to the inbox. Postmark allows you to send your application’s emails with high delivery rates, including bounce/spam processing and detailed statistics. In addition, Postmark can parse incoming emails which are forwarded back to your application.
The process of replying via email is known to be inbound.
How to implement Postmark in rails?
- Add add-on postmark in your Heroku or sign up using https://account.postmarkapp.com ( If you add postmark as an add-on in Heroku you do not need to sign up additionally).
- Create your server by adding the name of the server.
- You can create a signature or even skip this step.
- Since we are implementing inbound process, we will need our server’s inbound email address which can be found on the “Process inbound email” tab.
- Now you need to set `reply_to` (when sending email) with the given inbound email address (see example below).
- And at last you need to give the callback url. Postmark post JSON data each time an inbound event occurs (see screenshot below). In this callback portion, one can perform any necessary actions needed.
mail( to: <receiver's email>, subject: <subject>, reply_to: <server's inbound email address>)
Postmark also keeps tracks of the emails whether it is inbound or outbound. So you can check whether the email are being successfully processed or not.
If we need to send some important information that is required when the receiver replies the email s/he received, then we can add that information after a `+` sign in the `server’s inbound email address`.
Let’s say I need the `message_id` . Hence, I will add `+message<MESSAGEID>` or just `+<MESSAGEID>` to the email address. This additional details will appear in the JSON data under `MailboxHash` in the callback url we set in the server.