Sha256: 42e6bdc2151cea3538bffdf6534ae82f1576f7932cf91b7196f3ac41220af442

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

if (Rails.configuration.settings['shopapp_mailer_aws_key'] || Rails.configuration.settings['shopapp_aws_key']) &&
   !Rails.configuration.settings['skip_aws_sdk_shopapp_initialization']
  Aws::Rails.add_action_mailer_delivery_method(
    :aws_sdk,
    credentials: Aws::Credentials.new(
      (Rails.configuration.settings['shopapp_mailer_aws_key'] || Rails.configuration.settings['shopapp_aws_key']),
      (Rails.configuration.settings['shopapp_mailer_aws_secret'] || Rails.configuration.settings['shopapp_aws_secret'])
    ),
    region: (Rails.configuration.settings['aws_region'] || 'eu-west-1')
  )
end

class ShopappEmailInterceptor
  def self.delivering_email(message)
    unless Rails.configuration.settings['send_email'] == true
      message.perform_deliveries = false
      Rails.logger.warn "Not sending email because environment doesn't allow it."
      return
    end

    if Rails.configuration.settings['force_email_to'].present?
      message.to = Rails.configuration.settings['force_email_to']
      message.cc = nil
      message.bcc = nil
    end

    message.bcc = Rails.configuration.settings['force_email_bcc'] if Rails.configuration.settings['force_email_bcc'].present?
    message.from = Rails.configuration.settings['force_email_from'] if Rails.configuration.settings['force_email_from'].present?
  end
end

ActionMailer::Base.register_interceptor(ShopappEmailInterceptor)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shopapp-0.2.61 config/initializers/safe_email.rb
shopapp-0.2.60 config/initializers/safe_email.rb
shopapp-0.2.59 config/initializers/safe_email.rb
shopapp-0.2.58 config/initializers/safe_email.rb