LetterOpenerWeb::S3
Amazon S3 storage backend for letter_opener_web.
This gem allows you to store email letters and attachments on Amazon S3 instead of the local filesystem, enabling multi-instance deployments on platforms like Heroku, Kubernetes, or any containerized environment.
Installation
Add this line to your application's Gemfile:
gem 'letter_opener_web'
gem 'letter_opener_web-s3', require: 'letter_opener_web_s3'And then execute:
bundle installConfiguration
1. Configure AWS Credentials
Set up your AWS credentials and S3 bucket in your Rails configuration file (e.g., config/environments/development.rb):
# Require the gem first
require 'letter_opener_web_s3'
LetterOpenerWeb.configure do |config|
# Use the S3 storage backend
config.letter_class = LetterOpenerWeb::S3Letter
# AWS Configuration
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
config.aws_region = 'us-east-1'
config.aws_bucket = 'my-app-development-emails'
config.aws_bucket_prefix = 'letters' # Optional, defaults to 'letters'
end2. Configure ActionMailer
Update your ActionMailer configuration to use the S3 delivery method:
config.action_mailer.delivery_method = :letter_opener_web_s3Storage Structure
Emails are stored in S3 with the following structure (using default prefix letters):
YOUR-BUCKET-NAME/
└── letters/ # Configurable via aws_bucket_prefix
├── {timestamp_id_1}/
│ ├── plain.html
│ ├── rich.html
│ └── attachments/
│ ├── file1.pdf
│ └── file2.jpg
└── {timestamp_id_2}/
└── ...
You can customize the prefix by setting config.aws_bucket_prefix to organize emails under different paths in your bucket.
License
The gem is available as open source under the terms of the MIT License.