amazon-ses-mailer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in amazon-ses-mailer.gemspec
4
+ gemspec
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ amazon-ses-mailer (0.0.1)
5
+ ruby-hmac
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ ruby-hmac (0.4.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ amazon-ses-mailer!
17
+ ruby-hmac
data/README ADDED
@@ -0,0 +1,7 @@
1
+ Simple ruby class that implements Amazon SES API
2
+
3
+ Currently this only supports raw message sending.
4
+
5
+ Instructions
6
+ - Add your AWS access and secret keys
7
+ - Call deliver with your MIME encoded email as a param
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "amazon-ses-mailer/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "amazon-ses-mailer"
7
+ s.version = AmazonSes::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Eli Fox-Epstein", 'abronte']
10
+ s.email = ["eli@redhyphen.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Amazon SES mailer}
13
+ s.description = %q{Amazon SES mailer}
14
+
15
+ s.add_dependency "ruby-hmac"
16
+
17
+ s.rubyforge_project = "amazon-ses-mailer"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,72 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'hmac'
4
+ require 'hmac-sha2'
5
+ require 'base64'
6
+ require 'cgi'
7
+
8
+ module AmazonSes
9
+ class Mailer
10
+
11
+ def initialize(opts)
12
+ @version = opts[:version] || '2010-12-01'
13
+ @endpoint = opts[:endpoint] || 'https://email.us-east-1.amazonaws.com/'
14
+ @host = opts[:host] || 'email.us-east-1.amazonaws.com'
15
+
16
+ raise "Access key needed" unless opts.key? :access_key
17
+ raise "Secret key needed" unless opts.key? :secret_key
18
+
19
+ @access_key = opts[:access_key]
20
+ @secret_key = opts[:secret_key]
21
+ end
22
+
23
+ def deliver(msg)
24
+ @time = Time.now
25
+
26
+ http = Net::HTTP.new(@host, 443)
27
+ http.use_ssl = true
28
+
29
+ headers = { "x-amzn-authorization" => full_signature,
30
+ "Date" => sig_timestamp }
31
+
32
+ data = request_data(msg.to_s)
33
+
34
+ http.post("/", data, headers).body
35
+ end
36
+
37
+ def deliver_async(msg)
38
+ Thread.start do
39
+ resp = deliver(msg)
40
+ yield resp if block_given?
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def request_data(msg)
47
+ data = CGI::escape(Base64::encode64(msg))
48
+ time = CGI::escape(url_timestamp)
49
+
50
+ "AWSAccessKeyId=#{@access_key}&Action=SendRawEmail&RawMessage.Data=#{data}&Timestamp=#{time}&Version=#{@version}"
51
+ end
52
+
53
+ def url_timestamp
54
+ @time.gmtime.strftime('%Y-%m-%dT%H:%M:%S.000Z')
55
+ end
56
+
57
+ def sig_timestamp
58
+ @time.gmtime.strftime('%a, %d %b %Y %H:%M:%S GMT')
59
+ end
60
+
61
+ def generate_sig
62
+ msg = "#{sig_timestamp}"
63
+ hmac = HMAC::SHA256.new(@secret_key)
64
+ hmac.update(msg)
65
+ Base64::encode64(hmac.digest).chomp
66
+ end
67
+
68
+ def full_signature
69
+ "AWS3-HTTPS AWSAccessKey=#{@access_key}, Signature=#{generate_sig}, Algorithm=HmacSHA256"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ module AmazonSes
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amazon-ses-mailer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Eli Fox-Epstein
13
+ - abronte
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-26 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: ruby-hmac
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Amazon SES mailer
35
+ email:
36
+ - eli@redhyphen.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - Gemfile.lock
47
+ - README
48
+ - Rakefile
49
+ - amazon-ses-mailer.gemspec
50
+ - lib/amazon-ses-mailer.rb
51
+ - lib/amazon-ses-mailer/version.rb
52
+ has_rdoc: true
53
+ homepage: ""
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project: amazon-ses-mailer
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Amazon SES mailer
84
+ test_files: []
85
+