Amazon SES in 20 minutes

1) Sign into AWS account

2) Get your Account Security key, and secret key

3) add to bundle : gem ‘aws-ses’, :require => ‘aws/ses’

4) you are going to need to know that you are sandboxed - this means you can only send to - and send from emails that you verify.

here is a quick bit of code that you can drop in your rails ./script dir to verify emails and test the basics of the gem

- Begin file -

#!/usr/bin/env ruby
require File.expand_path('../../config/boot',  __FILE__)
require 'aws/ses'
class SesTool
  attr_reader :ses
  def initialize
    @ses = AWS::SES::Base.new(
      :access_key_id => 'KEY_HERE',
      :secret_access_key => 'SECRET_HERE')
  end
  def addresses_act(name,email)
    self.ses.addresses.send(name,email) unless email.blank?
  end
  def send_to(email,message)
    self.ses.send_email( :to => [email],
                        :source    => addresses_list.first,
                        :subject   => 'Subject Line',
                        :text_body => %%
  Stuff from ses_email\n
    #{message.inspect}
    %)
  end
  def addresses_list
    self.ses.addresses.list.result
  end
  def run(opts)
    opts = opts.dup
    case opts.shift
    when 'send' then
      puts 'send'
      send_to(opts.shift,opts)
    when 'list' then
      puts 'list'
      p addresses_list
    when 'verify' then
      addresses_act('verify',opts.shift)
    when 'delete' then
      addresses_act('delete',opts.shift)
    else
      puts 'nope'
    end
  end
end
SesTool.new.run(ARGV)

- End File -
Examples

ruby ses_email verify my_email@my_host.com
ruby ses_email verify my_email_2@my_host.com
# check your email and click the verify for both
ruby ses_email send my_email_2@my_host.com this is a message !
# done

Post a Comment

Your email is never shared. Required fields are marked *

*
*