Class: T::Mailer::Api::AwsSes

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/t/mailer/api/aws_ses.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#check_api_defined, #check_settings, #check_version_of, #field_value, #get_value_from, #using_gem

Constructor Details

#initialize(options) ⇒ AwsSes

Set settings and check if the required credentials are exist. If the credentials are missing then it will raise error.

Parameters:

  • options (Hash)

    with the credentials



15
16
17
18
19
20
# File 'lib/t/mailer/api/aws_ses.rb', line 15

def initialize(options)
  @settings = options

  check_settings(:aws_access_key_id, :aws_default_region,
    :aws_secret_access_key)
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



9
10
11
# File 'lib/t/mailer/api/aws_ses.rb', line 9

def settings
  @settings
end

Instance Method Details

#clientObject

Creates a client which will connect to server via API



23
24
25
26
27
28
29
# File 'lib/t/mailer/api/aws_ses.rb', line 23

def client
  credentials = Aws::Credentials.new(settings[:aws_access_key_id],
    settings[:aws_secret_access_key])
  region = settings[:aws_default_region]

  Aws::SES::Client.new(credentials: credentials, region: region)
end

#send_raw_email(params = {}) ⇒ Object

Composes an email message and immediately queues it for sending. When calling this operation, you may specify the message headers as well as the content. The ‘SendRawEmail` operation is particularly useful for sending multipart MIME emails (such as those that contain both a plain-text and an HTML version).

Examples:

Example: SendRawEmail


# The following example sends an email with an attachment:

resp = client.send_raw_email({
  destinations: [
  ],
  from_arn: "",
  raw_message: {
    data: "From: [email protected]\\nTo: [email protected]\\n
           Subject: Test email (contains an attachment)\\n
           MIME-Version: 1.0\\nContent-type: Multipart/Mixed;
           boundary=\"NextPart\"\\n\\n--NextPart\\n
           Content-Type: text/plain\\n\\nThis is the message body.\\n\\n
           --NextPart\\n
           Content-Type: text/plain;\\n
           Content-Disposition: attachment; filename=\"attachment.txt\"
           \\n\\nThis is the text in the attachment.\\n\\n--NextPart--",
  },
  return_path_arn: "",
  source: "",
  source_arn: "",
})

resp.to_h outputs the following:
{
  message_id: "EXAMPLEf3f73d99b-c63fb06f-d263-41f8-a0fb-d0dc67d56c07-000",
}

Request syntax with placeholder values


resp = client.send_raw_email({
  source: "Address",
  destinations: ["Address"],
  raw_message: {                                  # required
    data: "data",                                 # required
  },
  from_arn: "AmazonResourceName",
  source_arn: "AmazonResourceName",
  return_path_arn: "AmazonResourceName",
  tags: [
    {
      name: "MessageTagName",                     # required
      value: "MessageTagValue",                   # required
    },
  ],
  configuration_set_name: "ConfigurationSetName",
})

Response structure


resp.message_id #=> String

Parameters:

  • params (Hash) (defaults to: {})

    with the details of the email

Returns:

  • (Object)

    #<struct Aws::SES::Types::SendRawEmailResponse message_id=“an_id”>



96
97
98
# File 'lib/t/mailer/api/aws_ses.rb', line 96

def send_raw_email(params = {})
  client.send_raw_email(params)
end