Skip to content

Commit

Permalink
Merge pull request #2 from Teamtailor/mail-options
Browse files Browse the repository at this point in the history
SES options via mail headers
  • Loading branch information
himynameisjonas authored Oct 29, 2024
2 parents 6cc0f32 + b59053d commit 1a1d6a5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/mail/ses/options_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions spec/options_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" <from@abc.com>'
reply_to ["reply-to1@def.com", "", "My Reply-To <rt@qqq.com>"]
to ["to1@def.com", "My To <to2@xyz.com>", ""]
cc ["", "cc1@xyz.com", "My CC <cc2@def.com>"]
bcc ["My BCC <bcc1@abc.com>", "", "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 <from@abc.com>",
reply_to_addresses: ["reply-to1@def.com", "My Reply-To <rt@qqq.com>"],
destination: {
to_addresses: ["to1@def.com", "My To <to2@xyz.com>"],
cc_addresses: ["cc1@xyz.com", "My CC <cc2@def.com>"],
bcc_addresses: ["My BCC <bcc1@abc.com>", "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
Expand Down

0 comments on commit 1a1d6a5

Please sign in to comment.