Do you send lots of emails with your Rails app, and wish you had a way to spot check them? Fix those typos, and make sure the dynamic content looks correct? It’s easy to verify there are no code bugs with Rail’s builtin Mailer preview. But how do you prevent sending someone’s wrong order or personal information, especially if it’s in a batch of emails? You need to generate those emails, and make sure they match everything.
Introducing MailboxTester
Mailbox Tester is a Rails app that acts like an email SMTP provider service. It receives emails and displays them for your convenience. This is a great way to test out your emails, especially if there is complicated logic that might lead to subtle bugs in emails you send out. You can find the code here: https://github.com/OnRailsBlog/MailboxTester.
Using the new ActionMailbox framework, you can create an app that easily accepts emails. Since the goal is to see what arrived in the inbox, you’ll need an SMTP server to receive the email from your other app. Thankfully, there is no need for Postfix when you can use a ruby library, MidiSmtpServer to receive the emails, and route them to ActionMailbox.
Configuring your app
You need to tell your server to send mail to the SMTP service. MailboxTest listens at port 2525:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: '127.0.0.1', port: 2525 }
MailboxTester uses foreman to start the smtp service and the rails app that receives the emails from the SMTP service.
$ foreman start
Start sending emails from your app, and watch them appear on the MailboxTester page. You can see the text and html views, and make sure that every looks correct.
Let me know how this works for you!