Class: Mail::SES
- Inherits:
-
Object
- Object
- Mail::SES
- Defined in:
- lib/mail/ses.rb,
lib/mail/ses/version.rb,
lib/mail/ses/options_builder.rb,
lib/mail/ses/message_validator.rb
Overview
Mail delivery method handler for AWS SES
Defined Under Namespace
Classes: MessageValidator, OptionsBuilder
Constant Summary collapse
- VERSION =
'1.0.3'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
-
#deliver!(message, options = {}) ⇒ Object
Delivers a Mail::Message object via SES.
-
#initialize(options = {}) ⇒ SES
constructor
Initializes the Mail::SES object.
Constructor Details
#initialize(options = {}) ⇒ SES
Initializes the Mail::SES object.
options - The Hash options (optional, default: {}):
:mail_options - (Hash) Default AWS options to set on each mail object.
:error_handler - (Proc<Error, Hash>) Handler for AWS API errors.
:use_iam_profile - Shortcut to use AWS IAM instance profile.
All other options are passed-thru to Aws::SESV2::Client.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mail/ses.rb', line 20 def initialize( = {}) @mail_options = .delete(:mail_options) || {} @error_handler = .delete(:error_handler) raise ArgumentError.new(':error_handler must be a Proc') if @error_handler && !@error_handler.is_a?(Proc) @settings = { return_response: .delete(:return_response) } [:credentials] = Aws::InstanceProfileCredentials.new if .delete(:use_iam_profile) @client = Aws::SESV2::Client.new() end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/mail/ses.rb', line 11 def client @client end |
#settings ⇒ Object
Returns the value of attribute settings.
10 11 12 |
# File 'lib/mail/ses.rb', line 10 def settings @settings end |
Instance Method Details
#deliver!(message, options = {}) ⇒ Object
Delivers a Mail::Message object via SES.
message - The Mail::Message object to deliver (required). options - The Hash options which override any defaults set in :mail_options
in the initializer (optional, default: {}). Refer to
Aws::SESV2::Client#send_email
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mail/ses.rb', line 38 def deliver!(, = {}) MessageValidator.new().validate = @mail_options.merge( || {}) = OptionsBuilder.new(, ).build begin response = client.send_email() . = "#{response.to_h[:message_id]}@email.amazonses.com" settings[:return_response] ? response : self rescue StandardError => e handle_error(e, ) end end |