Rob Zolkos avatar

Rob Zolkos

January 5, 2024

Debugging Action Mailbox Issues in Production

When receiving and processing incoming emails with ActionMailbox, you may come across issues with particular emails that you need to debug. There is a tiny section in the Rails Guides about how to work with ActionMailbox in development. But how do we get an email that caused issues in production and debug it in development with the tools Rails provides?

To tackle this, the first step involves grabbing the raw email text from production. This is saved in the database for 30 days by default so you should have access to it. Open up your trusty rails production console:

inbound_email = ActionMailbox::InboundEmail.find(123)

Replace the 123 id with something relevant to your case. It may even be .last. You then need to output the raw email text

puts inbound_email.mail

Copy the email to your clipboard - you will need it for the next step.

Start up your Rails app in development and visit http://localhost:3000/rails/conductor/action_mailbox/inbound_emails

You’ll see a screen like this: Click on the New inbound email by source link.


Here you will be able to paste in the raw email source you copied from production:


Press the “Deliver inbound email” button and that will route that same email that was causing issues in production into your development system so you can debug it. From there you can halt execution at various points of the processing code and fix the issue [that is outside the scope of this post, but here are some handy guides.

Once you have found and fixed the issue, deployed the fix to production, all will be well. Not so fast. The fix will work for all future incoming mails. But what about the ones that didn’t work. The ones that failed before the fix?

They will need to be reprocessed. To do that, you need to know the id of the ones that didn’t work, and apply the reroute mechanism to process them again.

In the production console:

inbound_email = ActionMailbox::InboundEmail.find(id)

This will reprocess the incoming email with your fixes applied.