Skip to content
Merged
10 changes: 5 additions & 5 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

# Send mail through SES (see app/lib/ses_delivery_method.rb and
# config/initializers/action_mailer_ses.rb), authenticating via the instance/task's
# IAM role through the AWS SDK's standard credential chain - no explicit AWS
# credentials configured here.
# Send mail through SES. Registration (and the region setting) lives in
# config/initializers/action_mailer_ses.rb / app/lib/ses_delivery_method.rb, not
# here - see the comment there for why. Authenticates via the instance/task's IAM
# role through the AWS SDK's standard credential chain, no explicit AWS credentials
# configured here.
config.action_mailer.delivery_method = :ses
config.action_mailer.ses_settings = { region: ENV.fetch('AWS_REGION', 'us-east-1') }

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
Expand Down
8 changes: 7 additions & 1 deletion config/initializers/action_mailer_ses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
# before Zeitwerk has the app/lib root set up.
require Rails.root.join('app/lib/ses_delivery_method')

ActionMailer::Base.add_delivery_method :ses, SesDeliveryMethod
# Passed here, as add_delivery_method's default_options, rather than via
# config.action_mailer.ses_settings in config/environments/*.rb: referencing
# ActionMailer::Base below is what triggers its first load in this app, and Rails
# applies config.action_mailer.* settings via a load hook that fires on that same
# first load - so a `ses_settings=` assigned in production.rb would run before this
# add_delivery_method call has defined that setter, raising NoMethodError.
ActionMailer::Base.add_delivery_method :ses, SesDeliveryMethod, region: ENV.fetch('AWS_REGION', 'us-east-1')
Loading