POC for mailgun webhook and other APIs
To test following interfaces
- Send emails with a subject, text and campaign id to any email address
- Detect if an email address is listed in a suppressions (do not contact) list
- Get the list of previously sent emails to an email address
run MAILGUN_API_KEY=<key> MAILGUN_DOMAIN=<domain> rake
on console from application home directory
- Setup mailgun account and verify your email address.
- Copy the API keys and sandbox domain, which is to be used for this integration
- Create a Rails application, create two separate controllers - Webhook event handling and Event listing
- Download ngrok - This is needed to make the local URL s public so that mailgun can directly push the events. When we start ngrok using
ngrok http 3000
, it will give a dynamic URL. - Setup webhooks for “Open” and “Click” events in Mailgun account, Use the ngrok generated URLs.
- Opened event - This event needs an HTML email content, with image inside. Then only it would be able to track the event and ultimately webhook event will be fired to our Rails app.
- Clicked event - Similar to above, This event requires a HTML email with link, when this link is clicked then the event will be tracked and fired.
- We have only captured “Opened”/”Clicked” events in our controller, and stored in in the database table.
- Created another controller to list out the stored events.
Please start the server and visit http://localhost:3000/events to view open and click events