Skip to content

Commit

Permalink
Merge pull request #7 from mwlvandermaat/feature/save-to-sent-items-c…
Browse files Browse the repository at this point in the history
…onfig

Added configurable option for save_to_sent_items
  • Loading branch information
geisi authored Aug 16, 2023
2 parents 391c939 + 61e126e commit 96b86a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ You can install the package via composer:
```bash
composer require innoge/laravel-msgraph-mail
```

### Compatibility

Laravel 10.x and 9.x are supported.

## Configuration

### Register the Azure App

### Microsoft Azure AD Configuration

I have written a detailed Blog Post how you can configure your Microsoft Azure AD Tenant. [Sending Mails with Laravel and Microsoft Office 365 the secure way](https://geisi.dev/blog/getting-rid-of-deprecated-microsoft-office-365-smtp-mail-sending)

### I want to figure it out on my own
Expand Down Expand Up @@ -50,12 +53,17 @@ 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'),
],
'save_to_sent_items' => env('MAIL_SAVE_TO_SENT_ITEMS'),
],
```

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 `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.

Now you can switch your default mail driver to the new `microsoft-graph` driver by setting the env variable:

```dotenv
Expand All @@ -82,8 +90,8 @@ Please review [our security policy](../../security/policy) on how to report secu

## Credits

- [Tim Geisendoerfer](https://github.com/InnoGE)
- [All Contributors](../../contributors)
- [Tim Geisendoerfer](https://github.com/InnoGE)
- [All Contributors](../../contributors)

## License

Expand Down
4 changes: 2 additions & 2 deletions src/MicrosoftGraphTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function doSend(SentMessage $message): void
'sender' => $this->transformEmailAddress($envelope->getSender()),
'attachments' => $this->getAttachments($email),
],
'saveToSentItems' => false,
'saveToSentItems' => config('mail.mailers.microsoft-graph.save_to_sent_items', false),
];

$this->microsoftGraphApiService->sendMail($this->from, $payload);
Expand Down Expand Up @@ -86,7 +86,7 @@ protected function transformEmailAddress(Address $address): array
protected function getRecipients(Email $email, Envelope $envelope): Collection
{
return collect($envelope->getRecipients())
->filter(fn (Address $address) => ! in_array($address, array_merge($email->getCc(), $email->getBcc()), true));
->filter(fn (Address $address) => !in_array($address, array_merge($email->getCc(), $email->getBcc()), true));
}

protected function getAttachments(Email $email): array
Expand Down

0 comments on commit 96b86a1

Please sign in to comment.