Skip to content

Commit

Permalink
Merge branch 'support-different-message-id-domains'
Browse files Browse the repository at this point in the history
  • Loading branch information
himynameisjonas committed Oct 28, 2024
2 parents 4218c29 + 2d7e406 commit 7ac67b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/mail/ses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def initialize(options = {})
@error_handler = options.delete(:error_handler)
raise ArgumentError.new(':error_handler must be a Proc') if @error_handler && !@error_handler.is_a?(Proc)

@settings = { return_response: options.delete(:return_response) }
@settings = {
return_response: options.delete(:return_response),
message_id_domain: options.delete(:message_id_domain)
}

options[:credentials] = Aws::InstanceProfileCredentials.new if options.delete(:use_iam_profile)
@client = Aws::SESV2::Client.new(options)
Expand All @@ -43,7 +46,7 @@ def deliver!(message, options = {})

begin
response = client.send_email(send_options)
message.message_id = "#{response.to_h[:message_id]}@email.amazonses.com"
message.message_id = "#{response.to_h[:message_id]}@#{settings[:message_id_domain] || 'email.amazonses.com'}"
settings[:return_response] ? response : self
rescue StandardError => e
handle_error(e, send_options)
Expand Down
18 changes: 14 additions & 4 deletions spec/mail_ses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
describe '#settings' do
it do
expect(ses).to respond_to(:settings, :settings=)
expect(ses.settings).to eq(return_response: nil)
expect(ses.settings).to eq(return_response: nil, message_id_domain: nil)
end
end

Expand Down Expand Up @@ -99,9 +99,19 @@
end
end

it 'sets mail.message_id' do
ses.deliver!(mail)
expect(mail.message_id).to eq('[email protected]')
context "without message_id_domain config" do
it 'sets the default domain as mail.message_id' do
ses.deliver!(mail)
expect(mail.message_id).to eq('[email protected]')
end
end

context "with message_id_domain config" do
let(:ses_options) { { stub_responses: true, message_id_domain: 'eu-west-1.amazonses.com' } }
it 'sets as mail.message_id with the configured domain' do
ses.deliver!(mail)
expect(mail.message_id).to eq('[email protected]')
end
end

it 'returns the AWS response' do
Expand Down

0 comments on commit 7ac67b0

Please sign in to comment.