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 -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#!/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
1 2 3 4 5 6 |
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 |