Module: AWS::SES

Defined in:
lib/aws/ses/base.rb,
lib/aws/ses/info.rb,
lib/aws/ses/version.rb,
lib/aws/ses/response.rb,
lib/aws/ses/addresses.rb,
lib/aws/ses/send_email.rb

Overview

AWS::SES is a Ruby library for Amazon’s Simple Email Service’s REST API (aws.amazon.com/ses).

Getting started

To get started you need to require ‘aws/ses’:

% irb -rubygems
irb(main):001:0> require 'aws/ses'
# => true

Before you can do anything, you must establish a connection using Base.new. A basic connection would look something like this:

ses = AWS::SES::Base.new(
  :access_key_id     => 'abc', 
  :secret_access_key => '123'
)

The minimum connection options that you must specify are your access key id and your secret access key.

Connecting to a server from another region

The default server API endpoint is “email.us-east-1.amazonaws.com”, corresponding to the US East 1 region. To connect to a different one, just pass it as a parameter to the AWS::SES::Base initializer:

ses = AWS::SES::Base.new(
  :access_key_id     => 'abc', 
  :secret_access_key => '123',
  :server => 'email.eu-west-1.amazonaws.com',
  :message_id_domain => 'eu-west-1.amazonses.com'
)

Defined Under Namespace

Modules: Info, SendEmail, VERSION Classes: Addresses, Base, DeleteVerifiedEmailAddressResponse, EmailResponse, GetSendQuotaResponse, GetSendStatisticsResponse, ListVerifiedEmailAddressesResponse, Response, ResponseError, SendEmailResponse, SendRawEmailResponse, VerifyEmailAddressResponse

Constant Summary collapse

API_VERSION =
'2010-12-01'
DEFAULT_REGION =
'us-east-1'
SERVICE =
'ec2'
DEFAULT_HOST =
'email.us-east-1.amazonaws.com'
DEFAULT_MESSAGE_ID_DOMAIN =
'email.amazonses.com'
USER_AGENT =
'github-aws-ses-ruby-gem'
Version =
[VERSION::MAJOR, VERSION::MINOR, VERSION::TINY, VERSION::BETA].compact * '.'

Class Method Summary collapse

Class Method Details

.authorization_header(key, alg, sig) ⇒ Object

Generates the HTTP Header String that Amazon looks for

Parameters:

  • key (String)

    the AWS Access Key ID

  • alg (String)

    the algorithm used for the signature

  • sig (String)

    the signature itself



75
76
77
# File 'lib/aws/ses/base.rb', line 75

def SES.authorization_header(key, alg, sig)
  "AWS3-HTTPS AWSAccessKeyId=#{key}, Algorithm=#{alg}, Signature=#{sig}"
end

.authorization_header_v4(credential, signed_headers, signature) ⇒ Object



79
80
81
# File 'lib/aws/ses/base.rb', line 79

def SES.authorization_header_v4(credential, signed_headers, signature)
  "AWS4-HMAC-SHA256 Credential=#{credential}, SignedHeaders=#{signed_headers}, Signature=#{signature}"
end

.encode(secret_access_key, str, urlencode = true) ⇒ String

Encodes the given string with the secret_access_key by taking the hmac-sha1 sum, and then base64 encoding it. Optionally, it will also url encode the result of that to protect the string if it’s going to be used as a query string parameter.

Parameters:

  • secret_access_key (String)

    the user’s secret access key for signing.

  • str (String)

    the string to be hashed and encoded.

  • urlencode (Boolean) (defaults to: true)

    whether or not to url encode the result., true or false

Returns:

  • (String)

    the signed and encoded string.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/aws/ses/base.rb', line 57

def SES.encode(secret_access_key, str, urlencode=true)
  digest = OpenSSL::Digest.new('sha256')
  b64_hmac =
    Base64.encode64(
      OpenSSL::HMAC.digest(digest, secret_access_key, str)).gsub("\n","")

  if urlencode
    return CGI::escape(b64_hmac)
  else
    return b64_hmac
  end
end