mail-ses 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6828265477b50de02b28a33e6d7e6c2454489e1874a9ef4a877d5c9da2798c19
4
- data.tar.gz: b170ccac0a3decfc335bade3929bbabea31553b11f21f26abbf9af3d953bc083
3
+ metadata.gz: 91f1a759b15653521f07851f6706c4b9ed80eca19856e80033cb2052b42c0780
4
+ data.tar.gz: 923dacd96e29ca65e552214e8113e1ab56da0f5d27d0a0e28792a6d6e980eee4
5
5
  SHA512:
6
- metadata.gz: 4501f1de2cacc24c08c3a2f398ef1865c38661f6878f694db809e6cba04621f8e379a76e8c5d66770a10566f2ce5549571016fafe11681836bd70696a2519134
7
- data.tar.gz: f7c0310010dcdab52f961441b7c1c7f957bbaa815abe280e0bf90e36e2c42e3399d374d29f675e0af3507f8946ef5cdcef283c4085c0b847f409b1f03cc63de8
6
+ metadata.gz: 1b7321575bb49c5da7599a7c79e2db8f74cb18a5536eb78f40e49b774bec91c638dd59d91ef64a757b18fe879b65f90c6bb3b64038e9514fb881b419262dc475
7
+ data.tar.gz: 4e5c2cf40f609d9fe5ecfceb47b43f83a7c25a58d20c978ae4d26f5393f5c7a6688bb90a25fabd2222cb2f41e6d6e2064137c9c33a3ac08276a9d7a404233519
@@ -1,3 +1,7 @@
1
+ # 0.1.2
2
+
3
+ - Fix: Add #settings method for conformity with other Mail delivery methods.
4
+
1
5
  # 0.1.1
2
6
 
3
7
  - Fix: Remove Base64 encoding from message body.
data/README.md CHANGED
@@ -1,121 +1,123 @@
1
- [![Gem Version](https://badge.fury.io/rb/mail-ses.svg)](http://badge.fury.io/rb/mail-ses)
2
- [![Travis Status](https://travis-ci.org/tablecheck/mail-ses.svg?branch=master)](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
- * TBD
15
-
16
- ### Shameless Plug
17
-
18
- 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).
19
-
20
- ## Getting Started
21
-
22
- In your `Gemfile`:
23
-
24
- ```ruby
25
- gem 'mail-ses'
26
- ```
27
-
28
- Next, make a new initializer at `config/initializers/mail_ses.rb`:
29
-
30
- ```ruby
31
- ActionMailer::Base.add_delivery_method :ses, Mail::SES,
32
- region: 'us-east-1',
33
- access_key_id: 'abc',
34
- secret_access_key: '123'
35
- ```
36
-
37
- Finally, in the appropriate `config/environments/*.rb`:
38
-
39
- ```ruby
40
- config.action_mailer.delivery_method = :ses
41
- ```
42
-
43
- ## Advanced Usage
44
-
45
- ### AWS SES Client Options
46
-
47
- Any options supported by the `Aws::SES::Client` class can be passed into the initializer, for example:
48
-
49
- ```ruby
50
- ActionMailer::Base.add_delivery_method :ses, Mail::SES,
51
- region: 'us-east-1',
52
- session_token: 'foobar',
53
- retry_limit: 5,
54
- retry_max_delay: 10
55
- ```
56
-
57
- In addition, the shortcut option `:use_iam_profile (Boolean)` which activates the IAM instance profile.
58
-
59
- ```ruby
60
- ActionMailer::Base.add_delivery_method :ses, Mail::SES,
61
- region: 'us-east-1',
62
- use_iam_profile: true
63
- ```
64
-
65
- ### Default Mail Options
66
-
67
- In the initializer you can set `:mail_options (Hash)` which are default options to pass-through to each mail sent:
68
-
69
- ```ruby
70
- ActionMailer::Base.add_delivery_method :ses, Mail::SES,
71
- # ...
72
- mail_options: {
73
- source_arn: 'arn:aws:ses:us-east-1:123456789012:identity/example.com',
74
- tags: [
75
- { name: 'MessageTagName', value: 'MessageTagValue' },
76
- ],
77
- }
78
- ```
79
-
80
- ### AWS Error Handling
81
-
82
- To handle errors from AWS API, in the initializer you can set `:error_handler (Proc)` which takes two args:
83
- the error which was raised, and the raw_email options hash. This is useful for notifying your bug tracking service.
84
- Setting `:error_handler` causes the error to be swallowed unless it is raised again in the handler itself.
85
-
86
- ```ruby
87
- ActionMailer::Base.add_delivery_method :ses, Mail::SES,
88
- # ...
89
- error_handler: ->(error, raw_email) do
90
- Bugsnag.notify(error){|r| r.add_tab('email', { email: raw_email })}
91
- raise error
92
- end
93
- ```
94
-
95
- ### Send Email as a Standalone
96
-
97
- You can send one-off mails using the `Mail::SES` object and `#deliver` method.
98
-
99
- ```ruby
100
- mail = Mail.new(args)
101
-
102
- ses = Mail::SES.new(region: 'us-east-1',
103
- access_key_id: 'abc',
104
- secret_access_key: '123')
105
-
106
- options = { source_arn: 'arn:aws:ses:us-east-1:123456789012:identity/example.com' }
107
-
108
- ses.deliver!(mail, options) #=> returns AWS API response
109
-
110
- mail.message_id #=> "00000138111222aa-33322211-cccc-cccc-cccc-ddddaaaa0680-000000@email.amazonses.com"
111
- ```
112
-
113
- 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.
114
-
115
- ## Statistics, Verified Addresses, Bounce Rate, etc.
116
-
117
- Please use the official [AWS SDK v3 for SES](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-ruby.html).
118
-
119
- ## Copyright
120
-
121
- Copyright (c) 2018 TableCheck Inc. See LICENSE for further details.
1
+ [![Gem Version](https://badge.fury.io/rb/mail-ses.svg)](http://badge.fury.io/rb/mail-ses)
2
+ [![Travis Status](https://travis-ci.org/tablecheck/mail-ses.svg?branch=master)](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
1
+ 0.1.2
@@ -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
@@ -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(Seahorse::Client::Response)
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.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-18 00:00:00.000000000 Z
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