class AWS::SimpleEmailService

@return [Client] the low-level SimpleEmailService client object
@!attribute [r] client
end
puts “Complaints: #{stats}”
puts “Bounces: #{stats}”
puts “Rejects: #{stats}”
puts “Delivery Attempts: #{stats}”
puts “Sent: #{stats}”
ses.statistics.each do |stats|
You can get statistics about individual emails:
# Statistics
# => {:max_24_hour_send=>200, :max_send_rate=>1.0, :sent_last_24_hours=>22}
ses.quotas
24 hours):
To get your current quotas (and how many emails you have sent in the last
24-hour period.
* ‘:max_24_hour_send` - Maximum number of emails you can send in a
* `:max_send_rate` - Maximum number of emails you can send per second.
as follows:
send and how quickly you can send it. These sending limits are defined
Based on several factors, Amazon SES determines how much email you can
# Quotas
EMAIL
Sample email text.
Subject: A Sample Email
ses.send_raw_email(<<EMAIL, :to => ’to@foo.com’, :from => ‘from@foo.com’)
when sending raw emails:
If you prefer, you can also set the sender and recipient in ruby
EMAIL
Sample email text.
To: receipient@domain.com
From: sender@domain.com
Subject: A Sample Email
ses.send_raw_email(<<EMAIL)
that send_email does not support you can use {#send_raw_email}.
If you need to send email with attachments or have other special needs
:body_html => ‘<h1>Sample Email</h1>’)
:body_text => ‘Sample email text.’,
:to => ‘receipient@domain.com’,
:from => ‘sender@domain.com’,
:subject => ‘A Sample Email’,
ses.send_email(
To send a basic email you can use {#send_email}.
# Sending Email
identity.verification_token #=> ‘…’
identity.verified? #=> true/false
identity = ses.identities[‘yourdomain.com’]
# for a domain
identity.verified? #=> true/false
identity = ses.identities[‘youremail@yourdomain.com’]
# for an email address
You can get the verification status and token from identities as well.
email_addresses = ses.identities.email_addresses.map(&:identity)
domains = ses.identities.domains.map(&:identity)
You can filter the types of identities enumerated:
#=> [‘email@foo.com’, ‘somedomain.com’]
ses.identities.map(&:identity)
You can enumerate all identities:
## Listing Identities
more details.
the given verification token. See the service documentation for
You will be expected to update the DNS records for your domain with
#=> “216D+lZbhUL0zOoAkC83/0TAl5lJSzLmzsOjtXM7AeM=”
identity.verification_token
identity = ses.identities.verify(‘yourdomain.com’)
You can also verify an entire domain for sending and receiving emails.
## Verifying Domains
verify the email address.
You will be sent an email address with a link. Follow the link to
identity.verified? #=> false
identity = ses.identities.verify(‘email@yourdomain.com’)
the identities collection.
You can verify an email address for sending/receiving emails using
## Verifying Email Addresses
and domains.
you will only be able to send emails to and from verified email addresses
Until you have [requested production access](docs.amazonwebservices.com/ses/latest/DeveloperGuide/InitialSetup.Customer.html)
Identities are email addresses or domain names that you have control over.
Before you can send emails, you need to verify one or more identities.
# Identities
This has only been tested with Rails 2.3 and Rails 3.0.
config.action_mailer.delivery_method = :amazon_ses
2. Set SES as the delivery method:
1. Configure your AWS credentials with {AWS.config}
Rails application you just need to do 2 things:
If you want to use Amazon SimpleEmailService to send email from your
# Rails
:secret_access_key => ‘YOUR_SECRET_ACCESS_KEY’)
:access_key_id => ‘YOUR_ACCESS_KEY_ID’,
ses = AWS::SimpleEmailService.new(
Or you can set them directly on the SimpleEmailService interface:
:secret_access_key => ‘YOUR_SECRET_ACCESS_KEY’)
:access_key_id => ‘YOUR_ACCESS_KEY_ID’,
AWS.config(
AWS.config:
You can setup default credentials for all AWS services via
# Credentials
* [Amazon SimpleEmailService Documentation](aws.amazon.com/documentation/ses/)
* [Amazon SimpleEmailService](aws.amazon.com/ses/)
For more information about Amazon SimpleEmailService:
[sign up here](aws.amazon.com/ses/)
To use Amazon SimpleEmailService you must first
SimpleEmailService (SES).
This class is the starting point for working with Amazon

def email_addresses

Returns:
  • (EmailAddressCollection) - Returns a collection that represents

Other tags:
    Note: - This method is deprecated. Use {#identities} instead.
def email_addresses
  EmailAddressCollection.new(:config => config)
end

def identities

Returns:
  • (IdentityCollection) -
def identities
  IdentityCollection.new(:config => config)
end

def nest_options options, accepted_options

def nest_options options, accepted_options
  send_opts = {}
  accepted_options.each_pair do |option, keys|
    next unless options[option]
    hash = send_opts
    keys.collect{|k| k.to_sym }.each do |key|
      hash[key] = {} unless hash[key]
      if keys.last == key.to_s
        hash[key] = options[option]
      else
        hash = hash[key]
      end
    end
  end
  send_opts
end

def quotas

Returns:
  • (Hash) - Returns a hash of SES quotas and limits.
def quotas
  Quotas.new(:config => config).to_h
end

def require_each options, *keys

def require_each options, *keys
  keys.each do |key|
    unless options[key]
      raise ArgumentError, "missing required option :#{key}"
    end
  end
end

def require_one_of options, *keys

def require_one_of options, *keys
  unless keys.any?{|key| options[key] }
    parts = keys.collect{|key| ":#{key}" }.join(', ')
    raise ArgumentError, "you must provide at least one of #{parts}"
  end
end

def send_email options = {}

Returns:
  • (Core::Response) - the SendEmail response

Options Hash: (**options)
  • :body_html (String) --
  • :body_html_charset (String) -- The character set of the
  • :body_text_charset (String) -- The character set of the
  • :subject_charset (String) -- The character set of the
  • :body_html (String) -- The email html contents.
  • :body_text (String) -- The email text contents.
  • :return_path (String) -- The email address to which
  • :reply_to (String, Array) -- The reply-to email address(es)
  • :bcc (String, Array) -- The address(es) to bcc (blind
  • :cc (String, Array) -- The address(es) to cc (carbon copy)
  • :to (String, Array) -- The address(es) to send the email to.
  • :from (required, String) -- The sender's email address.
  • :subject (required, String) -- The subject of the message.

Parameters:
  • options (Hash) --
def send_email options = {}
    require_each(options, :subject, :from)
    require_one_of(options, :to, :cc, :bcc)
    require_one_of(options, :body_text, :body_html)
  # these three options can be passed strings or arrays of strings,
  # but the service requires them in a list (array)
  [:to, :cc, :bcc, :reply_to].each do |key|
    if options[key]
      options[key] = [options[key]].flatten
    end
  end
  accepted_options = {
    :subject           => %w(message subject data),
    :subject_charset   => %w(message subject charset),
    :to                => %w(destination to_addresses),
    :cc                => %w(destination cc_addresses),
    :bcc               => %w(destination bcc_addresses),
    :from              => %w(source),
    :reply_to          => %w(reply_to_addresses),
    :return_path       => %w(return_path),
    :body_text         => %w(message body text data),
    :body_text_charset => %w(message body text charset),
    :body_html         => %w(message body html data),
    :body_html_charset => %w(message body html charset),
  }
  client.send_email(nest_options(options, accepted_options))
end

def send_raw_email raw_message, options = {}

Returns:
  • (Core::Response) - the SendRawEmail response

Options Hash: (**options)
  • :from (String) -- The sender's email address.
  • :to (String, Array) -- One or more email addresses to

Parameters:
  • raw_message (required, String) -- The raw text of the message.
def send_raw_email raw_message, options = {}
  send_opts = {}
  send_opts[:raw_message] = {}
  send_opts[:raw_message][:data] = raw_message.to_s
  send_opts[:source] = options[:from] if options[:from]
  if raw_message.respond_to?(:destinations)
    send_opts[:destinations] = raw_message.destinations
  end
  send_opts[:destinations] = [options[:to]].flatten if options[:to]
  response = client.send_raw_email(send_opts)
  if raw_message.respond_to?(:message_id=)
    raw_message.message_id = "#{response.data[:message_id]}@email.amazonses.com"
  end
  response
end

def settings; {}; end

def settings; {}; end

def statistics

Returns:
  • (Array of Hashes) - An array of email statistic hashes.
def statistics
  response = client.get_send_statistics
  response.data[:send_data_points].collect do |data|
    {
      :sent => data[:timestamp],
      :delivery_attempts => data[:delivery_attempts],
      :rejects => data[:rejects],
      :bounces => data[:bounces],
      :complaints => data[:complaints],
    }
  end
end