mail-ses 0.1.1 → 1.0.1

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: 85feb11fd75e0a0af6ccc3c6a2d9711a48e9444db1fb2bec25f407a7388da165
4
+ data.tar.gz: d32dd2fe4aa147b3d1a08b1d65aa4cf92ce4001fd6318e23b9d05f0a7c97433a
5
5
  SHA512:
6
- metadata.gz: 4501f1de2cacc24c08c3a2f398ef1865c38661f6878f694db809e6cba04621f8e379a76e8c5d66770a10566f2ce5549571016fafe11681836bd70696a2519134
7
- data.tar.gz: f7c0310010dcdab52f961441b7c1c7f957bbaa815abe280e0bf90e36e2c42e3399d374d29f675e0af3507f8946ef5cdcef283c4085c0b847f409b1f03cc63de8
6
+ metadata.gz: 66f8925d0f8f0cc657b0fcb26868d1ee57010360747e5782f8126f28a5054004a6a20a5d3358608617eb900d5429adebbe16e0eaa9b98567f3ad048b806743c9
7
+ data.tar.gz: 339a15c00b6664a1266a3ea7dbe390ad684a434785fcc4670cb1f0a8c5b9409d3a7cc26892cf4c5d88a639c32c64671b1c56d224ec7ef9cc66188c9326b30506
data/CHANGELOG.md CHANGED
@@ -1,8 +1,26 @@
1
- # 0.1.1
2
-
3
- - Fix: Remove Base64 encoding from message body.
4
-
5
- # 0.1.0
6
-
7
- - Initial release of gem.
8
- - Support for sending ActionMailer mails via AWS SDK v3.
1
+ # Changelog
2
+
3
+ ### 1.0.1
4
+
5
+ - Add compatibility with Mail gem 2.8.0.
6
+
7
+ ### 1.0.0
8
+
9
+ - BREAKING CHANGE: Upgrade to AWS Ruby SDK v3 - SESv2 API ([@khrvi](https://github.com/khrvi))
10
+ - Drop support for Ruby 2.5 and earlier.
11
+ - Switch CI from Travis to Github Actions.
12
+ - Add Rubocop to CI.
13
+ - Refactor code.
14
+
15
+ ### 0.1.2
16
+
17
+ - Fix: Add #settings method for conformity with other Mail delivery methods.
18
+
19
+ ### 0.1.1
20
+
21
+ - Fix: Remove Base64 encoding from message body.
22
+
23
+ ### 0.1.0
24
+
25
+ - Initial release of gem.
26
+ - Support for sending ActionMailer mails via AWS SDK v3.
data/README.md CHANGED
@@ -1,121 +1,125 @@
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
+ [![Github Actions](https://github.com/tablecheck/mail-ses/actions/workflows/test.yml/badge.svg)](https://github.com/tablecheck/mail-ses/actions/workflows/test.yml)
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 for Ruby v3 - SESv2](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/SESV2.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.6+
15
+ * Ruby on Rails 3.2+
16
+ * AWS SDK for Ruby v3 - SESv2
17
+
18
+ Please use version 0.1.x of this gem for legacy Ruby and AWS SDK support.
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::SESV2::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
+ from_email_address_identity_arn: 'arn:aws:ses:us-east-1:123456789012:identity/example.com',
74
+ email_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 = { from_email_address_identity_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
+ ## Shameless Plug
120
+
121
+ Mail::SES is sponsored by [TableCheck](http://www.tablecheck.com/en/company/), 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).
122
+
123
+ ## Copyright
124
+
125
+ Copyright (c) 2018 [TableCheck Inc.](http://www.tablecheck.com/en/company/) See LICENSE for further details.
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mail
4
+ class SES
5
+ # Validates a Mail::Message object before sending
6
+ class MessageValidator
7
+ # message - The Mail::Message object to be validated.
8
+ def initialize(message)
9
+ @message = message
10
+ end
11
+
12
+ # Validate the message.
13
+ def validate
14
+ validate_class
15
+ validate_delivery_params
16
+ validate_attachments
17
+ end
18
+
19
+ private
20
+
21
+ def validate_class
22
+ return if @message.is_a?(Mail::Message)
23
+
24
+ raise ArgumentError.new('mail must be an instance of Mail::Message class')
25
+ end
26
+
27
+ def validate_delivery_params
28
+ if defined?(Mail::CheckDeliveryParams) # mail gem < 2.7.0
29
+ Mail::CheckDeliveryParams.check(@message)
30
+ elsif defined?(Mail::SmtpEnvelope) # mail gem >= 2.8.0
31
+ Mail::SmtpEnvelope.new(@message)
32
+ end
33
+ end
34
+
35
+ def validate_attachments
36
+ return unless @message.has_attachments? && @message.text_part.nil? && @message.html_part.nil?
37
+
38
+ raise ArgumentError.new('Attachment provided without message body')
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mail
4
+ class SES
5
+ # Builds options for Aws::SESV2::Client#send_email
6
+ class OptionsBuilder
7
+ # message - The Mail::Message object to be sent.
8
+ # options - The Hash options which override any defaults
9
+ # from the message.
10
+ def initialize(message, options = {})
11
+ @message = message
12
+ @options = options
13
+ end
14
+
15
+ # Returns the options for Aws::SESV2::Client#send_email.
16
+ def build
17
+ message_options.merge(ses_options)
18
+ end
19
+
20
+ private
21
+
22
+ def ses_options
23
+ slice_hash(@options, *RAW_EMAIL_ATTRS)
24
+ end
25
+
26
+ def message_options
27
+ {
28
+ from_email_address: @message.from&.first,
29
+ destination: {
30
+ to_addresses: Array(@message.to).compact,
31
+ cc_addresses: Array(@message.cc).compact,
32
+ bcc_addresses: Array(@message.bcc).compact
33
+ },
34
+ content: { raw: { data: @message.to_s } }
35
+ }.compact
36
+ end
37
+
38
+ def slice_hash(hash, *keys)
39
+ keys.each_with_object({}) { |k, h| h[k] = hash[k] if hash.key?(k) }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mail
4
+ class SES
5
+ VERSION = '1.0.1'
6
+ end
7
+ end
data/lib/mail/ses.rb CHANGED
@@ -1,87 +1,68 @@
1
- # frozen_string_literal: true
2
- module Mail
3
- # Mail delivery method handler for AWS SES
4
- class SES
5
- VERSION = File.read(File.join(File.dirname(__FILE__), '../../VERSION')).strip.freeze
6
-
7
- RAW_EMAIL_ATTRS = %i[ source
8
- source_arn
9
- from_arn
10
- return_path_arn
11
- tags
12
- configuration_set_name ].freeze
13
-
14
- attr_reader :client
15
-
16
- # Initializes the Mail::SES object.
17
- #
18
- # options - The Hash options (optional, default: {}):
19
- # :mail_options - (Hash) Default AWS options to set on each mail object.
20
- # :error_handler - (Proc<Error, Hash>) Handler for AWS API errors.
21
- # :use_iam_profile - Shortcut to use AWS IAM instance profile.
22
- # All other options are passed-thru to Aws::SES::Client.
23
- def initialize(options = {})
24
- @mail_options = options.delete(:mail_options) || {}
25
- @error_handler = options.delete(:error_handler)
26
- self.class.validate_error_handler(@error_handler)
27
- options = self.class.build_client_options(options)
28
- @client = Aws::SES::Client.new(options)
29
- end
30
-
31
- # Delivers a Mail object via SES.
32
- #
33
- # mail - The Mail object to deliver (required).
34
- # options - The Hash options which override any defaults set in :mail_options
35
- # in the initializer (optional, default: {}). Refer to
36
- # Aws::SES::Client#send_raw_email
37
- def deliver!(mail, options = {})
38
- self.class.validate_mail(mail)
39
- options = @mail_options.merge(options || {})
40
- raw_email_options = self.class.build_raw_email_options(mail, options)
41
- begin
42
- response = client.send_raw_email(raw_email_options)
43
- mail.message_id = "#{response.to_h[:message_id]}@email.amazonses.com"
44
- response
45
- rescue StandardError => e
46
- @error_handler ? @error_handler.call(e, raw_email_options.dup) : raise(e)
47
- end
48
- end
49
-
50
- class << self
51
- def validate_error_handler(error_handler)
52
- raise ArgumentError.new(':error_handler must be a Proc') if error_handler && !error_handler.is_a?(Proc)
53
- end
54
-
55
- def validate_mail(mail)
56
- unless mail.is_a?(Mail::Message)
57
- raise ArgumentError.new('mail must be an instance of Mail::Message class')
58
- end
59
-
60
- Mail::CheckDeliveryParams.check(mail)
61
-
62
- if mail.has_attachments? && mail.text_part.nil? && mail.html_part.nil?
63
- raise ArgumentError.new('Attachment provided without message body')
64
- end
65
- end
66
-
67
- def build_client_options(options)
68
- options[:credentials] = Aws::InstanceProfileCredentials.new if options.delete(:use_iam_profile)
69
- options
70
- end
71
-
72
- def build_raw_email_options(message, options = {})
73
- output = slice_hash(options, *RAW_EMAIL_ATTRS)
74
- output[:source] ||= message.from.first
75
- output[:destinations] = [message.to, message.cc, message.bcc].flatten.compact
76
- output[:raw_message] = { data: message.to_s }
77
- output
78
- end
79
-
80
- protected
81
-
82
- def slice_hash(hash, *keys)
83
- keys.each_with_object({}) { |k, h| h[k] = hash[k] if hash.key?(k) }
84
- end
85
- end
86
- end
87
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'mail/ses/version'
4
+ require 'mail/ses/message_validator'
5
+ require 'mail/ses/options_builder'
6
+
7
+ module Mail
8
+ # Mail delivery method handler for AWS SES
9
+ class SES
10
+ RAW_EMAIL_ATTRS = %i[ from_email_address
11
+ from_email_address_identity_arn
12
+ feedback_forwarding_email_address
13
+ feedback_forwarding_email_address_identity_arn
14
+ email_tags
15
+ configuration_set_name ].freeze
16
+
17
+ attr_accessor :settings
18
+ attr_reader :client
19
+
20
+ # Initializes the Mail::SES object.
21
+ #
22
+ # options - The Hash options (optional, default: {}):
23
+ # :mail_options - (Hash) Default AWS options to set on each mail object.
24
+ # :error_handler - (Proc<Error, Hash>) Handler for AWS API errors.
25
+ # :use_iam_profile - Shortcut to use AWS IAM instance profile.
26
+ # All other options are passed-thru to Aws::SESV2::Client.
27
+ def initialize(options = {})
28
+ @mail_options = options.delete(:mail_options) || {}
29
+
30
+ @error_handler = options.delete(:error_handler)
31
+ raise ArgumentError.new(':error_handler must be a Proc') if @error_handler && !@error_handler.is_a?(Proc)
32
+
33
+ @settings = { return_response: options.delete(:return_response) }
34
+
35
+ options[:credentials] = Aws::InstanceProfileCredentials.new if options.delete(:use_iam_profile)
36
+ @client = Aws::SESV2::Client.new(options)
37
+ end
38
+
39
+ # Delivers a Mail::Message object via SES.
40
+ #
41
+ # message - The Mail::Message object to deliver (required).
42
+ # options - The Hash options which override any defaults set in :mail_options
43
+ # in the initializer (optional, default: {}). Refer to
44
+ # Aws::SESV2::Client#send_email
45
+ def deliver!(message, options = {})
46
+ MessageValidator.new(message).validate
47
+
48
+ options = @mail_options.merge(options || {})
49
+ send_options = OptionsBuilder.new(message, options).build
50
+
51
+ begin
52
+ response = client.send_email(send_options)
53
+ message.message_id = "#{response.to_h[:message_id]}@email.amazonses.com"
54
+ settings[:return_response] ? response : self
55
+ rescue StandardError => e
56
+ handle_error(e, send_options)
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def handle_error(error, send_options)
63
+ raise(error) unless @error_handler
64
+
65
+ @error_handler.call(error, send_options.dup)
66
+ end
67
+ end
68
+ end
data/lib/mail-ses.rb CHANGED
@@ -1,4 +1,5 @@
1
- # frozen_string_literal: true
2
- require 'aws-sdk-ses'
3
- require 'mail'
4
- require 'mail/ses'
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sdk-sesv2'
4
+ require 'mail'
5
+ require 'mail/ses'
metadata CHANGED
@@ -1,29 +1,29 @@
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: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnny Shields
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-18 00:00:00.000000000 Z
11
+ date: 2022-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: aws-sdk-ses
14
+ name: aws-sdk-sesv2
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: '1.27'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
26
+ version: '1.27'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mail
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.2.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-smtp
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +100,14 @@ dependencies:
72
100
  requirements:
73
101
  - - "~>"
74
102
  - !ruby/object:Gem::Version
75
- version: 0.57.0
103
+ version: 1.30.1
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: 0.57.0
110
+ version: 1.30.1
83
111
  description: Ruby Mail delivery method handler for Amazon SES
84
112
  email: info@tablecheck.com
85
113
  executables: []
@@ -89,16 +117,17 @@ files:
89
117
  - CHANGELOG.md
90
118
  - LICENSE
91
119
  - README.md
92
- - VERSION
93
120
  - lib/mail-ses.rb
94
121
  - lib/mail/ses.rb
95
- - spec/mail_ses_spec.rb
96
- - spec/spec_helper.rb
122
+ - lib/mail/ses/message_validator.rb
123
+ - lib/mail/ses/options_builder.rb
124
+ - lib/mail/ses/version.rb
97
125
  homepage: https://github.com/tablecheck/mail-ses
98
126
  licenses:
99
127
  - MIT
100
- metadata: {}
101
- post_install_message:
128
+ metadata:
129
+ rubygems_mfa_required: 'true'
130
+ post_install_message:
102
131
  rdoc_options: []
103
132
  require_paths:
104
133
  - lib
@@ -106,18 +135,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
135
  requirements:
107
136
  - - ">="
108
137
  - !ruby/object:Gem::Version
109
- version: '0'
138
+ version: 2.6.0
110
139
  required_rubygems_version: !ruby/object:Gem::Requirement
111
140
  requirements:
112
141
  - - ">="
113
142
  - !ruby/object:Gem::Version
114
143
  version: '0'
115
144
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.7.3
118
- signing_key:
145
+ rubygems_version: 3.3.13
146
+ signing_key:
119
147
  specification_version: 4
120
148
  summary: Ruby Mail delivery method handler for Amazon SES
121
- test_files:
122
- - spec/mail_ses_spec.rb
123
- - spec/spec_helper.rb
149
+ test_files: []
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1
@@ -1,167 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- RSpec.describe Mail::SES do
5
- let(:ses_options) { { stub_responses: true } }
6
-
7
- let(:ses) do
8
- described_class.new(ses_options)
9
- end
10
-
11
- let(:mail) do
12
- Mail.new do
13
- from 'from@abc.com'
14
- to %w[to1@def.com to2@xyz.com]
15
- cc %w[cc1@xyz.com cc2@def.com]
16
- bcc %w[bcc1@abc.com bcc2@def.com]
17
- body 'This is the body'
18
- end
19
- end
20
-
21
- describe '::VERSION' do
22
- it { expect(described_class::VERSION).to match(/\A\d+\.\d+\.\d+/) }
23
- end
24
-
25
- describe '#initialize' do
26
- it 'accepts valid :error_handler' do
27
- expect(described_class.new(ses_options)).to be_a(Mail::SES)
28
- end
29
-
30
- it 'accepts valid :error_handler' do
31
- expect(described_class.new(ses_options.merge(error_handler: ->(a, b) {}))).to be_a(Mail::SES)
32
- end
33
-
34
- it 'rejects invalid :error_handler' do
35
- expect { described_class.new(ses_options.merge(error_handler: 'foobar')) }.to raise_error(ArgumentError, ':error_handler must be a Proc')
36
- end
37
-
38
- it 'handles :use_iam_profile option' do
39
- allow_any_instance_of(Aws::InstanceProfileCredentials).to receive(:get_credentials).and_return('{}')
40
- ses = described_class.new(ses_options.merge(use_iam_profile: true))
41
- expect(ses.client.config.credentials).to be_a(Aws::InstanceProfileCredentials)
42
- end
43
-
44
- it 'passes through options to AWS' do
45
- ses = described_class.new(ses_options.merge(log_level: :debug, retry_limit: 5))
46
- expect(ses.client.config.log_level).to eq :debug
47
- expect(ses.client.config.retry_limit).to eq 5
48
- end
49
- end
50
-
51
- describe '#deliver!' do
52
- it 'validates that mail is a Mail' do
53
- expect { ses.deliver!(foo: :bar) }.to raise_error(ArgumentError, 'mail must be an instance of Mail::Message class')
54
- end
55
-
56
- it 'validates integrity of Mail' do
57
- expect { ses.deliver!(Mail.new) }.to raise_error(ArgumentError, 'SMTP From address may not be blank: nil')
58
- expect { ses.deliver!(Mail.new { from 'foo@bar.com' }) }.to raise_error(ArgumentError, 'SMTP To address may not be blank: []')
59
- end
60
-
61
- it 'validates attachment without body' do
62
- mail.body = nil
63
- mail.add_file __FILE__
64
- expect { ses.deliver!(mail) }.to raise_error(ArgumentError, 'Attachment provided without message body')
65
- end
66
-
67
- context 'when options set' do
68
- before { allow(mail).to receive(:to_s).and_return('Fixed message body') }
69
- let(:ses_options) { { stub_responses: true, mail_options: { source: 'foo@bar.com', source_arn: 'sa1' } } }
70
-
71
- let(:exp) do
72
- {
73
- source: 'foo@bar.com',
74
- source_arn: 'sa2',
75
- destinations: %w[to1@def.com to2@xyz.com cc1@xyz.com cc2@def.com bcc1@abc.com bcc2@def.com],
76
- raw_message: {
77
- data: 'Fixed message body'
78
- }
79
- }
80
- end
81
-
82
- it 'allows pass-thru and override of default options' do
83
- expect(ses.client).to receive(:send_raw_email).with(exp)
84
- ses.deliver!(mail, source_arn: 'sa2')
85
- end
86
- end
87
-
88
- it 'sets mail.message_id' do
89
- ses.deliver!(mail)
90
- expect(mail.message_id).to eq('MessageId@email.amazonses.com')
91
- end
92
-
93
- it 'returns the AWS response' do
94
- expect(ses.deliver!(mail)).to be_a(Seahorse::Client::Response)
95
- end
96
-
97
- context 'error handling' do
98
- before { allow_any_instance_of(Aws::SES::Client).to receive(:send_raw_email).and_raise(RuntimeError.new('test')) }
99
-
100
- context 'when :error_handler not set' do
101
- it 'raises the error' do
102
- expect { ses.deliver!(mail) }.to raise_error(RuntimeError, 'test')
103
- end
104
- end
105
-
106
- context 'when :error_handler set' do
107
- let(:ses_options) { { stub_responses: true, error_handler: ->(a, b) {} } }
108
-
109
- it 'calls the error handler' do
110
- expect(ses_options[:error_handler]).to receive(:call).and_call_original
111
- ses.deliver!(mail)
112
- end
113
- end
114
- end
115
- end
116
-
117
- describe '::build_raw_email_options' do
118
- let(:options) { {} }
119
- subject { described_class.build_raw_email_options(mail, options) }
120
- before { allow(mail).to receive(:to_s).and_return('Fixed message body') }
121
-
122
- context 'without options' do
123
- let(:exp) do
124
- {
125
- source: 'from@abc.com',
126
- destinations: %w[to1@def.com to2@xyz.com cc1@xyz.com cc2@def.com bcc1@abc.com bcc2@def.com],
127
- raw_message: {
128
- data: 'Fixed message body'
129
- }
130
- }
131
- end
132
-
133
- it { expect(subject).to eq(exp) }
134
- end
135
-
136
- context 'with options' do
137
- let(:options) do
138
- { source: 'source@source.com',
139
- source_arn: 'source_arn',
140
- from_arn: 'from_arn',
141
- return_path_arn: 'return_path_arn',
142
- tags: [{ name: 'Name', value: 'Value' }],
143
- configuration_set_name: 'configuration_set_name',
144
- other: 'other' }
145
- end
146
-
147
- let(:exp) do
148
- {
149
- source: 'source@source.com',
150
- source_arn: 'source_arn',
151
- from_arn: 'from_arn',
152
- return_path_arn: 'return_path_arn',
153
- tags: [
154
- { name: 'Name', value: 'Value' }
155
- ],
156
- configuration_set_name: 'configuration_set_name',
157
- destinations: %w[to1@def.com to2@xyz.com cc1@xyz.com cc2@def.com bcc1@abc.com bcc2@def.com],
158
- raw_message: {
159
- data: 'Fixed message body'
160
- }
161
- }
162
- end
163
-
164
- it { expect(subject).to eq(exp) }
165
- end
166
- end
167
- end
data/spec/spec_helper.rb DELETED
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'rubygems'
3
- require 'bundler/setup'
4
- require 'rspec'
5
-
6
- Bundler.setup
7
-
8
- require 'mail-ses'
9
-
10
- RSpec.configure do |config|
11
- config.disable_monkey_patching!
12
-
13
- config.default_formatter = 'doc' if config.files_to_run.one?
14
-
15
- config.order = :random
16
-
17
- Kernel.srand config.seed
18
- end