diff --git a/lib/mail/ses/options_builder.rb b/lib/mail/ses/options_builder.rb index eb50a78..6c80ec8 100644 --- a/lib/mail/ses/options_builder.rb +++ b/lib/mail/ses/options_builder.rb @@ -22,7 +22,7 @@ def initialize(message, options = {}) # Returns the options for Aws::SESV2::Client#send_email. def build - message_options.merge(ses_options) + message_options.merge(ses_options, ses_options_from_message) end private @@ -32,6 +32,17 @@ def ses_options slice_hash(@options, *SES_FIELDS) end + def ses_options_from_message + mail_options = @message[:mail_options]&.unparsed_value + + if mail_options + @message[:mail_options] = nil + slice_hash(mail_options, *SES_FIELDS) + else + {} + end + end + def message_options { from_email_address: extract_value(:from)&.first, diff --git a/spec/options_builder_spec.rb b/spec/options_builder_spec.rb index dc697ed..eae25d3 100644 --- a/spec/options_builder_spec.rb +++ b/spec/options_builder_spec.rb @@ -102,6 +102,42 @@ it { expect(subject).to eq(exp) } end + context "with options on the mail object" do + let(:mail) do + Mail.new do + from '"My From" ' + reply_to ["reply-to1@def.com", "", "My Reply-To "] + to ["to1@def.com", "My To ", ""] + cc ["", "cc1@xyz.com", "My CC "] + bcc ["My BCC ", "", "bcc2@def.com"] + body "This is the body" + headers(mail_options: {email_tags: [{name: "Foo", value: "Bar"}]}) + end + end + + let(:exp) do + { + from_email_address: "My From ", + reply_to_addresses: ["reply-to1@def.com", "My Reply-To "], + destination: { + to_addresses: ["to1@def.com", "My To "], + cc_addresses: ["cc1@xyz.com", "My CC "], + bcc_addresses: ["My BCC ", "bcc2@def.com"] + }, + email_tags: [ + {name: "Foo", value: "Bar"} + ], + content: { + raw: { + data: "Fixed message body" + } + } + } + end + + it { expect(subject).to eq(exp) } + end + context "when addresses contain non-ascii chars" do let(:mail) do Mail.new do