InnoGE / laravel-msgraph-mail

Laravel Mail driver for Microsoft Office 365 using the MSGraph API
MIT License
26 stars 7 forks source link

[Bug]: From settings of email or notification are ignored #13

Closed sanderbaas closed 10 months ago

sanderbaas commented 10 months ago

What happened?

I have set the email from address in my .env file to info@company.org . When I send an email where I have specified another from address with ->from('support@company.org') the email is still sent from the email address that was specified in the config.

How to reproduce the bug

Set the EMAIL_FROM_ADDRESS in .env to one address and send an email with ->from('other@email.address').

Package Version

1.0.5

PHP Version

8.2

Laravel Version

10

Which operating systems does with happen with?

Linux

Notes

Perhaps https://github.com/InnoGE/laravel-msgraph-mail/blob/main/src/MicrosoftGraphTransport.php#L58 should be changed (untested):

old $this->microsoftGraphApiService->sendMail($this->from, $payload);

new $this->microsoftGraphApiService->sendMail($this->transformEmailAddresses(collect($email->getFrom())), $payload);

geisi commented 10 months ago

Hi @sanderbaas,

Thank you for bringing this issue to our attention. I've attempted to replicate the problem using our test suite, but so far, I haven't been able to reproduce it. You can review the added test I conducted here: MicrosoftGraphTransportTest.php. It is within the "the configured mail sender can be overwritten" test.

Based on these tests, the MSGraph Mailer appears to be functioning correctly. However, I'm keen to understand more about your experience. Could you provide some additional details or specific steps that might help us reproduce the issue on our end?

Looking forward to your response.

sanderbaas commented 10 months ago

Hi @geisi ,

Thank you for your rapid response. I have done some tests myself and indeed the payload that is sent to Microsoft Graph contains the correct sender info. However, the endpoint that is used also contains the from email address.

It is being supplied here: https://github.com/InnoGE/laravel-msgraph-mail/blob/main/src/LaravelMsGraphMailServiceProvider.php#L45 and eventually used here to create the actual API request: https://github.com/InnoGE/laravel-msgraph-mail/blob/main/src/MicrosoftGraphTransport.php#L58

When I manually change $this->from into other email address, the email I receive indeed has the correct sender. But maybe I do not understand Microsoft Graph and it has to do with some settings...

geisi commented 10 months ago

Thank you @sanderbaas

I have fixed this issue just update your dependencies, and it should work as expected.

Thank you! https://github.com/InnoGE/laravel-msgraph-mail/releases/tag/1.1.0

sanderbaas commented 10 months ago

Thanks @geisi it is working now!