Class: Aws::Rails::Sesv2Mailer
- Inherits:
-
Object
- Object
- Aws::Rails::Sesv2Mailer
- 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
-
#deliver!(message) ⇒ Object
Rails expects this method to exist, and to handle a Mail::Message object correctly.
-
#initialize(options = {}) ⇒ Sesv2Mailer
constructor
A new instance of Sesv2Mailer.
-
#settings ⇒ Object
ActionMailer expects this method to be present and to return a hash.
Constructor Details
#initialize(options = {}) ⇒ Sesv2Mailer
Returns a new instance of Sesv2Mailer.
21 22 23 24 |
# File 'lib/aws/rails/sesv2_mailer.rb', line 21 def initialize( = {}) @client = SESV2::Client.new() @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!() params = { content: { raw: { data: .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] = .smtp_envelope_from if .instance_variable_get(:@smtp_envelope_from) params[:destination] = { to_addresses: to_addresses(), cc_addresses: .cc, bcc_addresses: .bcc } @client.send_email(params).tap do |response| .header[:ses_message_id] = response. end end |
#settings ⇒ Object
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 |