Skip to content

Blogging On Rails

Everything on Rails!

Introducing Mailbox Tester

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:

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: '', 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!

Looking to make your Rails app more interactive?

Subscribe below, and you won’t miss the next Rails tutorial, that will teach you how to make really interactive web apps that just work.

We won’t send you spam. Unsubscribe at any time.

2 comments on “Introducing Mailbox Tester”

  1. Hey John, have you ever used used letter_opener? If so, what’s the difference? Letter opener fills my need at the moment, but I’m open to trying something new that makes much more sense to use in development. I have one application under my wing where the core feature is sending out emails. So, your gem might be very useful.

    Thanks once again.

    1. I didn’t see this. Thanks for sharing.

      My use case is similar to letter_opener. I personally wanted to understand ActionMailbox more, hence why it runs as it’s own application locally on your computer.

      I think Mailbox Tester might be useful if you’re going to send hundreds of emails at once. Looking over the docs, it seems letter_opener would open lots of tabs/windows, whereas Mailbox Tester is a CRUD app that you can page through.

Leave a Reply

Your email address will not be published. Required fields are marked *