Skip to content

Add configurable send_as address with envelope fallback #45

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ 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),
],
```

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.
Expand Down
5 changes: 4 additions & 1 deletion src/MicrosoftGraphTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down