Class: Aws::Rails::Sesv2Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/rails/sesv2_mailer.rb

Overview

Provides a delivery method for ActionMailer that uses Amazon Simple Email Service V2.

Once you have an SESv2 delivery method you can configure Rails to use this for ActionMailer in your environment configuration (e.g. RAILS_ROOT/config/environments/production.rb)

config.action_mailer.delivery_method = :sesv2

Uses the AWS SDK for Ruby’s credential provider chain when creating an SESV2 client instance.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Sesv2Mailer

Returns a new instance of Sesv2Mailer.

Parameters:



21
22
23
24
# File 'lib/aws/rails/sesv2_mailer.rb', line 21

def initialize(options = {})
  @client = SESV2::Client.new(options)
  @client.config.user_agent_frameworks << 'aws-sdk-rails'
end

Instance Method Details

#deliver!(message) ⇒ Object

Rails expects this method to exist, and to handle a Mail::Message object correctly. Called during mail delivery.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aws/rails/sesv2_mailer.rb', line 28

def deliver!(message)
  params = { content: { raw: { data: message.to_s } } }
  # smtp_envelope_from will default to the From address *without* sender names.
  # By omitting this param, SESv2 will correctly use sender names from the mail headers.
  # We should only use smtp_envelope_from when it was explicitly set (instance variable set)
  params[:from_email_address] = message.smtp_envelope_from if message.instance_variable_get(:@smtp_envelope_from)
  params[:destination] = {
    to_addresses: to_addresses(message),
    cc_addresses: message.cc,
    bcc_addresses: message.bcc
  }

  @client.send_email(params).tap do |response|
    message.header[:ses_message_id] = response.message_id
  end
end

#settingsObject

ActionMailer expects this method to be present and to return a hash.



46
47
48
# File 'lib/aws/rails/sesv2_mailer.rb', line 46

def settings
  {}
end