How to debug Mailgun email handling in local Rails development environment

I’m working on a Rails application that’s deployed on Heroku and uses Mailgun for handling incoming emails. The problem I’m facing is that I can’t test my email processing logic locally. Right now I have to deploy to Heroku every time I want to test changes to my email handler code, which is really slow and annoying.

Is there a way to set up Mailgun to work with my local development server? I need to be able to receive and process emails on localhost so I can debug my code faster. This is just a personal project so I don’t need a complex setup.

Any suggestions on how to configure this would be really helpful.

You could also use the letter_opener gem to intercept emails during development. It won’t mimic Mailgun’s webhook flow exactly, but you’ll see how your emails get processed without external services. I’ve found this really helpful for email parsing logic since you can manually trigger handlers with test data. For something more complete, try Mailcatcher - it runs locally and catches all outbound emails. But if you specifically need to test Mailgun’s incoming email webhooks, ngrok is probably your best bet for personal projects.

ngrok is the best! Just install it and run ngrok http 3000 - it opens your localhost for you. Update your Mailgun webhook with the ngrok URL. It really saved me when I had the same problem with my Rails app.

I encountered a similar issue and found a practical solution. Instead of exposing your local environment, set up a dedicated test endpoint in your Rails application that can handle POST requests in the format expected by Mailgun’s webhooks. This lets you use tools like curl or Postman to simulate incoming emails with sample data, allowing you to debug your email logic without relying on external services. It significantly speeds up testing, especially when dealing with edge cases or invalid data. Just remember to restrict access to this endpoint so it remains isolated from your production environment.