Rails Mailer Sandbox ๐ฌ
Catch Rails emails locally before they escape into the wild. Rails Mailer Sandbox stores
real .eml messages and gives you a Mailtrap-inspired inbox right inside your Rails app.
No SMTP server, database, account, or monthly bill needed.
โจ What You Get
- Persistent MIME messages across Rails restarts
- Search by subject, sender, recipient, or full body
- HTML, plain-text, and raw-source views
- Desktop, tablet, and mobile preview widths
- From, To, Cc, Bcc, date, and message-size details
- Inline
cid:image previews and attachment downloads - UTF-8 attachment filenames
- Automatic inbox refresh without repeatedly parsing every email
- Individual and bulk deletion
- Sandboxed HTML previews with scripts and remote resources blocked
- Filesystem locking and atomic writes for Rails and background workers
๐ Get Started
Add gem to development group:
group :development do
gem "rails-mailer-sandbox"
end
Set it up:
bundle install
bundle exec rake rails_mailer_sandbox:setup
Restart Rails, send any Action Mailer email, then visit:
๐ http://localhost:3000/rails_mailer_sandbox
Setup creates config/initializers/rails_mailer_sandbox.rb, configures Action Mailer,
and mounts Web UI. Run task again safely; it will not overwrite edited initializer.
๐ง Manual Setup
Prefer doing it yourself? Add this to config/environments/development.rb:
config.action_mailer.delivery_method = :rails_mailer_sandbox
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
Mount inbox in config/routes.rb:
mount RailsMailerSandbox::Server.new => "/rails_mailer_sandbox" if Rails.env.development?
๐พ Where Emails Live
Default path: Rails.root/tmp/rails_mailer_sandbox.
Want another location? Set it in initializer:
RailsMailerSandbox.storage_path = Rails.root.join("storage", "development_mail")
Keep custom storage out of version control. bin/rails tmp:clear removes default inbox.
Filesystem storage targets local development on one host, not distributed deployments or
giant email archives.
๐งช Development
git clone https://github.com/azmi2409/rails-mailer-sandbox.git
cd rails-mailer-sandbox
bundle install
bundle exec ruby -Ilib test/rails_mailer_sandbox_test.rb
gem build rails-mailer-sandbox.gemspec
CI runs tests and gem build on Ruby 3.0, 3.1, 3.2, and 3.3. Found a bug or have a neat focused improvement? Read CONTRIBUTING.md, then open an issue or pull request. ๐
Release notes live in CHANGELOG.md. ๐
๐ One Important Rule
Use this gem in development only. Captured emails may contain reset links, personal data, or other secrets. Never expose mounted inbox publicly or enable it in production.
๐ License
MIT. Build useful things and test your emails. ๐