mail-ses 0.1.1 → 0.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +123 -121
- data/VERSION +1 -1
- data/lib/mail/ses.rb +3 -1
- data/spec/mail_ses_spec.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91f1a759b15653521f07851f6706c4b9ed80eca19856e80033cb2052b42c0780
|
4
|
+
data.tar.gz: 923dacd96e29ca65e552214e8113e1ab56da0f5d27d0a0e28792a6d6e980eee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b7321575bb49c5da7599a7c79e2db8f74cb18a5536eb78f40e49b774bec91c638dd59d91ef64a757b18fe879b65f90c6bb3b64038e9514fb881b419262dc475
|
7
|
+
data.tar.gz: 4e5c2cf40f609d9fe5ecfceb47b43f83a7c25a58d20c978ae4d26f5393f5c7a6688bb90a25fabd2222cb2f41e6d6e2064137c9c33a3ac08276a9d7a404233519
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,121 +1,123 @@
|
|
1
|
-
[](http://badge.fury.io/rb/mail-ses)
|
2
|
-
[](https://travis-ci.org/tablecheck/mail-ses)
|
3
|
-
|
4
|
-
# Mail::SES
|
5
|
-
|
6
|
-
Mail::SES is a mail delivery method handler for Amazon SES (Simple Email Service) which can be used with Rails' [Action Mailer](https://guides.rubyonrails.org/action_mailer_basics.html).
|
7
|
-
|
8
|
-
This gem is inspired by [Drew Blas' AWS::SES gem](https://github.com/drewblas/aws-ses),
|
9
|
-
but uses the official [AWS SDK v3 for SES](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-ruby.html) under-the-hood.
|
10
|
-
By passing parameters through to the SDK, this gem supports greater flexibility with less code (including IAM instance profiles, retry parameters, etc.)
|
11
|
-
|
12
|
-
### Compatibility
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
mail
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
Copyright
|
1
|
+
[](http://badge.fury.io/rb/mail-ses)
|
2
|
+
[](https://travis-ci.org/tablecheck/mail-ses)
|
3
|
+
|
4
|
+
# Mail::SES
|
5
|
+
|
6
|
+
Mail::SES is a mail delivery method handler for Amazon SES (Simple Email Service) which can be used with Rails' [Action Mailer](https://guides.rubyonrails.org/action_mailer_basics.html).
|
7
|
+
|
8
|
+
This gem is inspired by [Drew Blas' AWS::SES gem](https://github.com/drewblas/aws-ses),
|
9
|
+
but uses the official [AWS SDK v3 for SES](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-ruby.html) under-the-hood.
|
10
|
+
By passing parameters through to the SDK, this gem supports greater flexibility with less code (including IAM instance profiles, retry parameters, etc.)
|
11
|
+
|
12
|
+
### Compatibility
|
13
|
+
|
14
|
+
* Ruby 2.1+
|
15
|
+
* Ruby on Rails 3.2+
|
16
|
+
* AWS SDK v3
|
17
|
+
|
18
|
+
### Shameless Plug
|
19
|
+
|
20
|
+
ActionMailer::SES is sponsored by [TableCheck](http://corp.tablecheck.com/), Japan's leading restaurant management app. If **you** are a ninja-level Javascript/Ruby coder, designer, project manager, etc. and are eager to work in Tokyo with other ninjas, Japan in a dynamic environment, please get in touch at [careers@tablecheck.com](mailto:careers@tablecheck.com).
|
21
|
+
|
22
|
+
## Getting Started
|
23
|
+
|
24
|
+
In your `Gemfile`:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'mail-ses'
|
28
|
+
```
|
29
|
+
|
30
|
+
Next, make a new initializer at `config/initializers/mail_ses.rb`:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
ActionMailer::Base.add_delivery_method :ses, Mail::SES,
|
34
|
+
region: 'us-east-1',
|
35
|
+
access_key_id: 'abc',
|
36
|
+
secret_access_key: '123'
|
37
|
+
```
|
38
|
+
|
39
|
+
Finally, in the appropriate `config/environments/*.rb`:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
config.action_mailer.delivery_method = :ses
|
43
|
+
```
|
44
|
+
|
45
|
+
## Advanced Usage
|
46
|
+
|
47
|
+
### AWS SES Client Options
|
48
|
+
|
49
|
+
Any options supported by the `Aws::SES::Client` class can be passed into the initializer, for example:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
ActionMailer::Base.add_delivery_method :ses, Mail::SES,
|
53
|
+
region: 'us-east-1',
|
54
|
+
session_token: 'foobar',
|
55
|
+
retry_limit: 5,
|
56
|
+
retry_max_delay: 10
|
57
|
+
```
|
58
|
+
|
59
|
+
In addition, the shortcut option `:use_iam_profile (Boolean)` which activates the IAM instance profile.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
ActionMailer::Base.add_delivery_method :ses, Mail::SES,
|
63
|
+
region: 'us-east-1',
|
64
|
+
use_iam_profile: true
|
65
|
+
```
|
66
|
+
|
67
|
+
### Default Mail Options
|
68
|
+
|
69
|
+
In the initializer you can set `:mail_options (Hash)` which are default options to pass-through to each mail sent:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
ActionMailer::Base.add_delivery_method :ses, Mail::SES,
|
73
|
+
# ...
|
74
|
+
mail_options: {
|
75
|
+
source_arn: 'arn:aws:ses:us-east-1:123456789012:identity/example.com',
|
76
|
+
tags: [
|
77
|
+
{ name: 'MessageTagName', value: 'MessageTagValue' },
|
78
|
+
],
|
79
|
+
}
|
80
|
+
```
|
81
|
+
|
82
|
+
### AWS Error Handling
|
83
|
+
|
84
|
+
To handle errors from AWS API, in the initializer you can set `:error_handler (Proc)` which takes two args:
|
85
|
+
the error which was raised, and the raw_email options hash. This is useful for notifying your bug tracking service.
|
86
|
+
Setting `:error_handler` causes the error to be swallowed unless it is raised again in the handler itself.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
ActionMailer::Base.add_delivery_method :ses, Mail::SES,
|
90
|
+
# ...
|
91
|
+
error_handler: ->(error, raw_email) do
|
92
|
+
Bugsnag.notify(error){|r| r.add_tab('email', { email: raw_email })}
|
93
|
+
raise error
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
### Send Email as a Standalone
|
98
|
+
|
99
|
+
You can send one-off mails using the `Mail::SES` object and `#deliver` method.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
mail = Mail.new(args)
|
103
|
+
|
104
|
+
ses = Mail::SES.new(region: 'us-east-1',
|
105
|
+
access_key_id: 'abc',
|
106
|
+
secret_access_key: '123')
|
107
|
+
|
108
|
+
options = { source_arn: 'arn:aws:ses:us-east-1:123456789012:identity/example.com' }
|
109
|
+
|
110
|
+
ses.deliver!(mail, options) #=> returns AWS API response
|
111
|
+
|
112
|
+
mail.message_id #=> "00000138111222aa-33322211-cccc-cccc-cccc-ddddaaaa0680-000000@email.amazonses.com"
|
113
|
+
```
|
114
|
+
|
115
|
+
Please also see the [AWS SDK v3 for SES](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-ruby.html) for alternate approaches.
|
116
|
+
|
117
|
+
## Statistics, Verified Addresses, Bounce Rate, etc.
|
118
|
+
|
119
|
+
Please use the official [AWS SDK v3 for SES](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-ruby.html).
|
120
|
+
|
121
|
+
## Copyright
|
122
|
+
|
123
|
+
Copyright (c) 2018 TableCheck Inc. See LICENSE for further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/mail/ses.rb
CHANGED
@@ -11,6 +11,7 @@ module Mail
|
|
11
11
|
tags
|
12
12
|
configuration_set_name ].freeze
|
13
13
|
|
14
|
+
attr_accessor :settings
|
14
15
|
attr_reader :client
|
15
16
|
|
16
17
|
# Initializes the Mail::SES object.
|
@@ -23,6 +24,7 @@ module Mail
|
|
23
24
|
def initialize(options = {})
|
24
25
|
@mail_options = options.delete(:mail_options) || {}
|
25
26
|
@error_handler = options.delete(:error_handler)
|
27
|
+
@settings = { return_response: options.delete(:return_response) }
|
26
28
|
self.class.validate_error_handler(@error_handler)
|
27
29
|
options = self.class.build_client_options(options)
|
28
30
|
@client = Aws::SES::Client.new(options)
|
@@ -41,7 +43,7 @@ module Mail
|
|
41
43
|
begin
|
42
44
|
response = client.send_raw_email(raw_email_options)
|
43
45
|
mail.message_id = "#{response.to_h[:message_id]}@email.amazonses.com"
|
44
|
-
response
|
46
|
+
settings[:return_response] ? response : self
|
45
47
|
rescue StandardError => e
|
46
48
|
@error_handler ? @error_handler.call(e, raw_email_options.dup) : raise(e)
|
47
49
|
end
|
data/spec/mail_ses_spec.rb
CHANGED
@@ -22,6 +22,13 @@ RSpec.describe Mail::SES do
|
|
22
22
|
it { expect(described_class::VERSION).to match(/\A\d+\.\d+\.\d+/) }
|
23
23
|
end
|
24
24
|
|
25
|
+
describe '#settings' do
|
26
|
+
it do
|
27
|
+
expect(ses).to respond_to(:settings, :settings=)
|
28
|
+
expect(ses.settings).to eq(return_response: nil)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
25
32
|
describe '#initialize' do
|
26
33
|
it 'accepts valid :error_handler' do
|
27
34
|
expect(described_class.new(ses_options)).to be_a(Mail::SES)
|
@@ -91,7 +98,15 @@ RSpec.describe Mail::SES do
|
|
91
98
|
end
|
92
99
|
|
93
100
|
it 'returns the AWS response' do
|
94
|
-
expect(ses.deliver!(mail)).to be_a(
|
101
|
+
expect(ses.deliver!(mail)).to be_a(Mail::SES)
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when :return_response set' do
|
105
|
+
let(:ses_options) { { stub_responses: true, return_response: true } }
|
106
|
+
|
107
|
+
it 'returns the AWS response' do
|
108
|
+
expect(ses.deliver!(mail)).to be_a(Seahorse::Client::Response)
|
109
|
+
end
|
95
110
|
end
|
96
111
|
|
97
112
|
context 'error handling' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail-ses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johnny Shields
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-ses
|