Search code examples
ruby-on-railsherokuemailmailgun

Rails: test mailgun on localhost


I have a Rails app running on Heroku that uses Mailgun to process incoming emails. I haven't been able to figure how I can debug my email processing locally (on localhost) instead of having to push everything up to heroku every time I make a change. (this is just a test app - I'm the only one using it)

Is it possible to work with Mailgun locally? If so, how do I go about it?

Thank you in advance


Solution

  • Mailgun gives you the option to store a message for later retrieval. If you configure it that way, you'll be able to fetch messages from development for processing without having to set up a publicly-accessible webhook for Mailgun to hit.

    But I'm assuming you have production configured with an HTTP endpoint, and it's no fun to do things differently between environments. There are a few tools that will let you set up a public endpoint that routes to localhost:

    • ngrok, which I've used to good effect to test Twilio. You can set up a permanent subdomain so you don't have to constantly change your Mailgun configuration.
    • UltraHook, which I haven't personally used, but looks the same.
    • Localtunnel which looks easiest to start up, but like you get a different host at every boot.

    If you have a permanent publicly-accessible server, you can also maintain your own tunnel.