Class: Aws::Rails::Mailer

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

Overview

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

Once you have an SES 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 = :aws_sdk

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mailer

Returns a new instance of Mailer.

Parameters:



19
20
21
# File 'lib/aws/rails/mailer.rb', line 19

def initialize(options = {})
  @client = SES::Client.new(options)
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.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/aws/rails/mailer.rb', line 25

def deliver!(message)
  send_opts = {}
  send_opts[:raw_message] = {}
  send_opts[:raw_message][:data] = message.to_s

  if message.respond_to?(:destinations)
    send_opts[:destinations] = message.destinations
  end

  @client.send_raw_email(send_opts)

end

#settingsObject

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



39
40
41
# File 'lib/aws/rails/mailer.rb', line 39

def settings
  {}
end