class T::Mailer::DeliverySystem::AwsSes

Attributes

settings[R]

Public Class Methods

new(options = {}) click to toggle source

Set settings with the required credentials for the API, but allow to call this delivery system without it.

@param [Hash] options with the credentials

# File lib/t/mailer/delivery_system/aws_ses.rb, line 13
def initialize(options = {})
  @settings = options
end

Public Instance Methods

deliver(message) click to toggle source

Check that the API is loaded. If API is missing it will raise error. If API exists then it will call the API with the generated options from the given mail message.

@param [Mail::Message] message what we would like to send

@return [Mail::Message] message with the changed message_id

# File lib/t/mailer/delivery_system/aws_ses.rb, line 24
def deliver(message)
  check_api_defined("Api::AwsSes")

  options = generate_options(message)

  response = Api::AwsSes.new(settings).send_raw_email(options)
  message.message_id = response && response.message_id

  message
end
generate_options(message) click to toggle source

Generate the required hash what it will send via API.

@param [Mail::Message] message what we would like to send

@return [Hash] options for the API

# File lib/t/mailer/delivery_system/aws_ses.rb, line 40
def generate_options(message)
  {
    raw_message:            {
      data: message.to_s,
    },
    tags:                   [
      {
        name:  message.delivery_handler.to_s,
        value: get_value_from(message["tag"]),
      },
    ],
    configuration_set_name: get_value_from(message["configuration_set_name"]),
  }
end