module AWS::SES

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'
)

Constants

API_VERSION
DEFAULT_HOST
DEFAULT_MESSAGE_ID_DOMAIN
DEFAULT_REGION
SERVICE
USER_AGENT
Version

Public Class Methods

authorization_header(key, alg, sig) click to toggle source

Generates the HTTP Header String that Amazon looks for

@param [String] key the AWS Access Key ID @param [String] alg the algorithm used for the signature @param [String] sig the signature itself

# 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) click to toggle source
# 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) click to toggle source

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.

@param [String] secret_access_key the user's secret access key for signing. @param [String] str the string to be hashed and encoded. @param [Boolean] urlencode whether or not to url encode the result., true or false @return [String] the signed and encoded string.

# 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