diff --git a/config/environments/production.rb b/config/environments/production.rb index 63270ae..19fefdf 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -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). diff --git a/config/initializers/action_mailer_ses.rb b/config/initializers/action_mailer_ses.rb index 81bed49..78968a6 100644 --- a/config/initializers/action_mailer_ses.rb +++ b/config/initializers/action_mailer_ses.rb @@ -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')