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
- RAW_EMAIL_ATTRS =
%i[ from_email_address from_email_address_identity_arn feedback_forwarding_email_address feedback_forwarding_email_address_identity_arn email_tags configuration_set_name ].freeze
- VERSION =
'1.0.1'
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.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mail/ses.rb', line 27 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.
18 19 20 |
# File 'lib/mail/ses.rb', line 18 def client @client end |
#settings ⇒ Object
Returns the value of attribute settings.
17 18 19 |
# File 'lib/mail/ses.rb', line 17 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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mail/ses.rb', line 45 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 |