RobertJoseph
RobertJoseph

Reputation: 8158

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

Upvotes: 5

Views: 8158

Answers (3)

OuttaSpaceTime
OuttaSpaceTime

Reputation: 966

using this gem might be another possible solution:

https://github.com/ryanb/letter_opener/ or https://github.com/fgrehm/letter_opener_web for more advanced features

  • follow installation from repo
  • mail will open in new tab

Upvotes: 0

Avinash
Avinash

Reputation: 419

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.

Upvotes: 1

Kristján
Kristján

Reputation: 18803

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.

Upvotes: 12

Related Questions