docker-rails-example icon indicating copy to clipboard operation
docker-rails-example copied to clipboard

feat: add mailcatcher docker image for development

Open ThomAille opened this issue 2 years ago • 7 comments

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

ThomAille avatar Aug 19 '22 16:08 ThomAille

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?

nickjj avatar Aug 19 '22 16:08 nickjj

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.

ThomAille avatar Aug 19 '22 23:08 ThomAille

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.

nickjj avatar Aug 20 '22 21:08 nickjj

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/

ThomAille avatar Aug 23 '22 11:08 ThomAille

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!

nickjj avatar May 03 '23 12:05 nickjj

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:

  • add mount LetterOpenerWeb::Engine => '/letter_opener' if Rails.env.development? to routes.rb
  • set config.action_mailer.delivery_method = :letter_opener_web in development.rb

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.

Birdie0 avatar Jul 22 '23 18:07 Birdie0

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.

nickjj avatar Jul 22 '23 20:07 nickjj