Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SES options via mail headers #2

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" <[email protected]>'
reply_to ["[email protected]", "", "My Reply-To <[email protected]>"]
to ["[email protected]", "My To <[email protected]>", ""]
cc ["", "[email protected]", "My CC <[email protected]>"]
bcc ["My BCC <[email protected]>", "", "[email protected]"]
body "This is the body"
headers(mail_options: {email_tags: [{name: "Foo", value: "Bar"}]})
end
end

let(:exp) do
{
from_email_address: "My From <[email protected]>",
reply_to_addresses: ["[email protected]", "My Reply-To <[email protected]>"],
destination: {
to_addresses: ["[email protected]", "My To <[email protected]>"],
cc_addresses: ["[email protected]", "My CC <[email protected]>"],
bcc_addresses: ["My BCC <[email protected]>", "[email protected]"]
},
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
Loading