From a16f20c0d7f49d2cab0662b5c0b0be5a28effcf9 Mon Sep 17 00:00:00 2001 From: mirkin-pixel <45396064+mirkin-pixel@users.noreply.github.com> Date: Thu, 17 Apr 2025 10:05:00 +0200 Subject: [PATCH] feat(mail): add config-based send_as with envelope fallback The sender address for outgoing emails is now determined via the `mail.mailers.microsoft-graph.send_as` config value. If this value is not set, it falls back to the envelope's sender address (`$envelope->getSender()->getAddress()`), ensuring emails can still be sent without explicit configuration. --- README.md | 3 +++ src/MicrosoftGraphTransport.php | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5451ab9..8042450 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ First you need to add a new entry to the mail drivers array in your `config/mail 'address' => env('MAIL_FROM_ADDRESS'), 'name' => env('MAIL_FROM_NAME'), ], + 'send_as' => env('MAIL_SEND_AS'), 'save_to_sent_items' => env('MAIL_SAVE_TO_SENT_ITEMS', false), ], ``` @@ -56,6 +57,8 @@ First you need to add a new entry to the mail drivers array in your `config/mail For the `client_id`, `client_secret` and `tenant_id` you need to use the values from the Azure App you created in the previous step. +The `send_as` option is the email address which is the sender. When left blank then the default sender is used from the `from.address` parameter. To use a different sender the `from.address` (Azure User) must have access to this mailbox. + The `save_to_sent_items` option in Microsoft Graph refers to a parameter that determines whether a sent email should be saved to the sender's "Sent Items" folder within their mailbox. When this option is set to true, the email will be automatically saved to the "Sent Items" folder, providing a record of the communication. Conversely, when it's set to false, the email will not be saved to the "Sent Items" folder. By default, the save_to_sent_items option is set to false, which means that emails sent through Microsoft Graph won't be saved in the sender's "Sent Items" folder unless explicitly specified otherwise. This behavior can be useful in scenarios where you might want more control over which emails are saved as sent items, perhaps to reduce clutter or ensure confidentiality. diff --git a/src/MicrosoftGraphTransport.php b/src/MicrosoftGraphTransport.php index aac89be..4cd1bbe 100644 --- a/src/MicrosoftGraphTransport.php +++ b/src/MicrosoftGraphTransport.php @@ -63,7 +63,10 @@ protected function doSend(SentMessage $message): void $payload['message']['internetMessageHeaders'] = $headers; } - $this->microsoftGraphApiService->sendMail($envelope->getSender()->getAddress(), $payload); + $this->microsoftGraphApiService->sendMail(!empty(config('mail.mailers.microsoft-graph.send_as')) + ? config('mail.mailers.microsoft-graph.send_as') + : $envelope->getSender()->getAddress(), + $payload); } /**