Sha256: 37ff10ffb7f9ad54e8a67fec3139a275b15bbe8f19095aaf0a69aebb942b674b

Contents?: true

Size: 1.49 KB

Versions: 10

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require 'aws-sdk-ses'

module Aws
  module Rails
    # 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 = :ses
    #
    # Uses the AWS SDK for Ruby's credential provider chain when creating an SES
    # client instance.
    class Mailer
      # @param [Hash] options Passes along initialization options to
      #   [Aws::SES::Client.new](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/SES/Client.html#initialize-instance_method).
      def initialize(options = {})
        @client = SES::Client.new(options)
      end

      # Rails expects this method to exist, and to handle a Mail::Message object
      # correctly. Called during mail delivery.
      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).tap do |response|
          message.header[:ses_message_id] = response.message_id
        end
      end

      # ActionMailer expects this method to be present and to return a hash.
      def settings
        {}
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
aws-sdk-rails-3.6.4 lib/aws/rails/mailer.rb
aws-sdk-rails-3.6.3 lib/aws/rails/mailer.rb
aws-sdk-rails-3.6.2 lib/aws/rails/mailer.rb
aws-sdk-rails-3.6.1 lib/aws/rails/mailer.rb
aws-sdk-rails-3.6.0 lib/aws/rails/mailer.rb
aws-sdk-rails-3.5.0 lib/aws/rails/mailer.rb
aws-sdk-rails-3.4.0 lib/aws/rails/mailer.rb
aws-sdk-rails-3.3.0 lib/aws/rails/mailer.rb
aws-sdk-rails-3.2.1 lib/aws/rails/mailer.rb
aws-sdk-rails-3.1.0 lib/aws/rails/mailer.rb