feat: update Resend email delivery method to use headers for sender and recipient

This commit is contained in:
gabrieljablonski 2025-04-02 09:38:04 -03:00
parent a119641c21
commit 217cecae9e
2 changed files with 15 additions and 12 deletions

View File

@ -6,9 +6,9 @@ module Mail # rubocop:disable Style/ClassAndModuleChildren
def deliver!(mail)
Resend::Emails.send(
from: mail.smtp_envelope_from,
to: mail.smtp_envelope_to,
subject: mail.subject,
from: mail.header[:from].to_s,
to: mail.header[:to].to_s,
subject: mail.header[:subject].to_s,
html: mail.decoded,
text: sanitize_html(mail.decoded)
)

View File

@ -3,11 +3,14 @@ require 'rails_helper'
describe Mail::ResendProvider do
let(:provider) { described_class.new({}) }
let(:mail) do
instance_double(Mail::Message,
smtp_envelope_from: 'sender@example.com',
smtp_envelope_to: ['receiver@example.com'],
subject: 'Test Email',
decoded: '<p>This is a test email message.</p>')
Mail::Message.new(
headers: {
from: 'Sender <sender@example.com>',
to: ['Receiver <receiver@example.com>'],
subject: 'Test Email'
},
body: '<p>This is a test email message.</p>'
)
end
describe '#deliver!' do
@ -15,8 +18,8 @@ describe Mail::ResendProvider do
response = instance_double(HTTParty::Response, success?: true)
allow(Resend::Emails).to receive(:send)
.with(
from: 'sender@example.com',
to: ['receiver@example.com'],
from: 'Sender <sender@example.com>',
to: 'Receiver <receiver@example.com>',
subject: 'Test Email',
html: '<p>This is a test email message.</p>',
text: 'This is a test email message.'
@ -32,8 +35,8 @@ describe Mail::ResendProvider do
it 'raises a DeliveryError with the error message' do
allow(Resend::Emails).to receive(:send)
.with(
from: 'sender@example.com',
to: ['receiver@example.com'],
from: 'Sender <sender@example.com>',
to: 'Receiver <receiver@example.com>',
subject: 'Test Email',
html: '<p>This is a test email message.</p>',
text: 'This is a test email message.'