nickjj / docker-rails-example

A production ready example Rails app that's using Docker and Docker Compose.
MIT License
975 stars 197 forks source link

feat: add mailcatcher docker image for development #46

Open ThomAille opened 2 years ago

ThomAille commented 2 years ago

Added mailcatcher to allow developers to test sending and integrating emails in development

nickjj commented 2 years ago

Hi,

I appreciate the PR and contribution but sorry no thanks. Rails has built in support for this using https://www.seancdavis.com/posts/preview-emails-in-rails/. It lets you preview any email in a browser without sending out an email. Did you encounter issues using this approach?

ThomAille commented 2 years ago

Hi I have not encountered any problem with email preview. However, the rendering is not faithful to the rendering of an email box. The Rails preview is played in a web browser which is much more permissive than a mailbox. it is for this reason that I add mailcatcher in addition to my rails project to have a rendering closer to an email client.

nickjj commented 2 years ago

Fair enough, it looks like mailcatcher supports both a web UI and being able to see it in a real mail client.

I'll leave this PR open because I do in general like the idea. Sometimes the Rails mail preview solution is troublesome because you want to see the mail from another user or something tied into a job firing off and you don't want to use a hard coded example.

Let me think about this for a bit if you don't mind.

ThomAille commented 2 years ago

No problem, I already use this version for my personal projects and I update it when necessary. At the moment I added storybook and web compoments to my project.

https://viewcomponent.org/ https://jonspalmer.github.io/view_component_storybook/ https://storybook.js.org/

nickjj commented 1 year ago

In case anyone is curious, I have been using MailCatcher for about 6 months and it's really good. I ended up making a blog post and video about it here: https://nickjanetakis.com/blog/self-host-and-preview-emails-locally-with-mailcatcher-open-source

I think it'll make its way into this project at some point. Thanks for introducing it to me ThomAille!

Birdie0 commented 1 year ago

What's about using letter_opener_web gem instead? Previously I was using mailcatcher too, but it was complicating setup a bit as it needed to be running on background beforehand.

The setup of letter_opener_web is pretty straightforward:

All new letters ever sent will be available on the dashboard at http://localhost:3000/letter_opener

Emails data will be stored locally at tmp/letter_opener (can be configured).

UPD: mailpit can be considered as quite good alternative and it provides some nice features like email client compatibility stats.

nickjj commented 1 year ago

I mainly prefer it because it works with any tech stack. It's also decoupled from Rails which makes it a bit more compatible with your app. For example Letter Opener hasn't had a commit in 1.5+ years, if it stops working with the next version of Rails we'd have to wait for a patch. With MailCatcher it will work no matter what version of Rails you have.

Also with Docker it becomes a service you can add to your docker-compose.yml file and not think about it again. In development it gets run with the rest of your services. Thanks to Docker Compose profiles you can also choose not to run it by setting a single env var.

Ultimately both do similar things, feel free to stick with Letter Opener if you prefer it.