Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 762
RobertJoseph Avatar asked Dec 15 '22 12:12

RobertJoseph


2 Answers

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.

like image 188
Kristján Avatar answered Jan 04 '23 02:01

Kristján


mailgun provides a sandbox that you can use for localhost the only downside to this is that you have to add the test email to valid recipient.

like image 21
Avinash Avatar answered Jan 04 '23 03:01

Avinash