amazon-ses-mailer 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +34 -0
- data/amazon-ses-mailer.gemspec +1 -0
- data/lib/amazon-ses-mailer.rb +17 -6
- data/lib/amazon-ses-mailer/version.rb +1 -1
- metadata +16 -3
- data/README +0 -7
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Amazon SES Mailer
|
2
|
+
Implements Amazon SES API.
|
3
|
+
|
4
|
+
## Options
|
5
|
+
- `access_key`: your AWS access key
|
6
|
+
- `secret_key`: your AWS secret key
|
7
|
+
- `version`: API version
|
8
|
+
- `endpoint`: SES endpoint URL
|
9
|
+
- `host`: SES endpoint host
|
10
|
+
|
11
|
+
# Limitations
|
12
|
+
Currently it only supports raw message sending.
|
13
|
+
|
14
|
+
# Examples
|
15
|
+
|
16
|
+
Create a mailer instance
|
17
|
+
|
18
|
+
mailer = AmazonSES::Mailer.new(secret_key: __, access_key: __)
|
19
|
+
|
20
|
+
Deliver a message
|
21
|
+
|
22
|
+
mailer.deliver to: 'foo@example.com',
|
23
|
+
from: 'bar@example.com',
|
24
|
+
subject: 'This is a subject',
|
25
|
+
body: 'And this is the body'
|
26
|
+
|
27
|
+
Other delivery options
|
28
|
+
|
29
|
+
mail = Mail.new { ... }
|
30
|
+
m.deliver(mail)
|
31
|
+
|
32
|
+
File.open('/path/to/raw/email') do |f|
|
33
|
+
m.deliver(f.read)
|
34
|
+
end
|
data/amazon-ses-mailer.gemspec
CHANGED
data/lib/amazon-ses-mailer.rb
CHANGED
@@ -4,6 +4,7 @@ require 'hmac'
|
|
4
4
|
require 'hmac-sha2'
|
5
5
|
require 'base64'
|
6
6
|
require 'cgi'
|
7
|
+
require 'mail'
|
7
8
|
|
8
9
|
module AmazonSes
|
9
10
|
class Mailer
|
@@ -22,14 +23,18 @@ module AmazonSes
|
|
22
23
|
|
23
24
|
def deliver(msg)
|
24
25
|
@time = Time.now
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
if @endpoint.start_with? 'https'
|
28
|
+
http = Net::HTTP.new(@host, 443)
|
29
|
+
http.use_ssl = true
|
30
|
+
else
|
31
|
+
http = Net::HTTP.new(@host)
|
32
|
+
end
|
28
33
|
|
29
34
|
headers = { "x-amzn-authorization" => full_signature,
|
30
35
|
"Date" => sig_timestamp }
|
31
36
|
|
32
|
-
data = request_data(msg
|
37
|
+
data = request_data(msg)
|
33
38
|
|
34
39
|
http.post("/", data, headers).body
|
35
40
|
end
|
@@ -37,14 +42,20 @@ module AmazonSes
|
|
37
42
|
def deliver_async(msg)
|
38
43
|
Thread.start do
|
39
44
|
resp = deliver(msg)
|
40
|
-
yield resp if block_given?
|
45
|
+
yield resp if block_given?
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
49
|
private
|
45
50
|
|
46
51
|
def request_data(msg)
|
47
|
-
|
52
|
+
msg_str = if Hash === msg
|
53
|
+
Mail.new(msg).to_s
|
54
|
+
else
|
55
|
+
msg.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
data = CGI::escape(Base64::encode64(msg_str))
|
48
59
|
time = CGI::escape(url_timestamp)
|
49
60
|
|
50
61
|
"AWSAccessKeyId=#{@access_key}&Action=SendRawEmail&RawMessage.Data=#{data}&Timestamp=#{time}&Version=#{@version}"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Eli Fox-Epstein
|
@@ -31,6 +31,19 @@ dependencies:
|
|
31
31
|
version: "0"
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: mail
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
34
47
|
description: Amazon SES mailer
|
35
48
|
email:
|
36
49
|
- eli@redhyphen.com
|
@@ -44,7 +57,7 @@ files:
|
|
44
57
|
- .gitignore
|
45
58
|
- Gemfile
|
46
59
|
- Gemfile.lock
|
47
|
-
- README
|
60
|
+
- README.md
|
48
61
|
- Rakefile
|
49
62
|
- amazon-ses-mailer.gemspec
|
50
63
|
- lib/amazon-ses-mailer.rb
|