|
| 1 | +# dot-mail-outlook |
| 2 | + |
| 3 | +Dotkernel's Microsoft Outlook ESMTP email service. |
| 4 | + |
| 5 | +> dot-mail-outlook is a wrapper on top of [dotkernel/dot-mail](https://github.com/dotkernel/dot-mail) |
| 6 | +
|
| 7 | +## Badges |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +[](https://github.com/dotkernel/dot-mail-outlook/issues) |
| 13 | +[](https://github.com/dotkernel/dot-mail-outlook/network) |
| 14 | +[](https://github.com/dotkernel/dot-mail-outlook/stargazers) |
| 15 | +[](https://github.com/dotkernel/dot-mail-outlook/blob/0.1/LICENSE.md) |
| 16 | + |
| 17 | +[](https://github.com/dotkernel/dot-mail-outlook/actions/workflows/continuous-integration.yml) |
| 18 | +[](https://codecov.io/gh/dotkernel/dot-mail-outlook) |
| 19 | +[](https://github.com/dotkernel/dot-mail/actions/workflows/static-analysis.yml) |
| 20 | + |
1 | 21 | ## Installation |
2 | 22 |
|
3 | | -Uses the "client credentials" flow from Microsoft for generating the bearer token: |
4 | | -* https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow |
5 | | -* https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth |
| 23 | +Install `dotkernel/dot-mail-outlook` by executing the following Composer command: |
| 24 | + |
| 25 | +```shell |
| 26 | +composer require dotkernel/dot-mail-outlook |
| 27 | +``` |
| 28 | + |
| 29 | +Register `src/ConfigProvider.php` in `config/config.php` by adding the following line: |
| 30 | + |
| 31 | +```php |
| 32 | +\Dot\MailOutlook\ConfigProvider::class, |
| 33 | +``` |
| 34 | + |
| 35 | +## Configuration |
6 | 36 |
|
7 | 37 | Copy the `dot-mail-outlook.local` file to your `autoload` folder (or copy its contents to `mail.global.php`) and fill in the relevant information. |
8 | 38 |
|
9 | | -`Dot-mail` configuration **MUST** use the `esmtp` transport under the `dot_mail.default.transport` key. |
| 39 | +```php |
| 40 | +<?php |
| 41 | + |
| 42 | +declare(strict_types=1); |
| 43 | + |
| 44 | +$tenant = ''; |
| 45 | + |
| 46 | +return [ |
| 47 | + 'xoauth2_outlook' => [ |
| 48 | + "tokenCacheFile" => '', |
| 49 | + "tenant" => $tenant, |
| 50 | + "access_code_url" => "https://login.microsoftonline.com/{$tenant}/oauth2/v2.0/token", |
| 51 | + "client_id" => '', |
| 52 | + "client_secret" => '', |
| 53 | + "scope" => 'https://outlook.office.com/.default', |
| 54 | + "grant_type" => 'client_credentials', |
| 55 | + ], |
| 56 | +]; |
| 57 | +``` |
| 58 | + |
| 59 | +The `dotkernel/dot-mail` config file should be updated to make sure the necessary options are set: |
| 60 | + |
| 61 | +- `transport` **MUST** be set to under the `dot_mail.default.transport` key. |
| 62 | +- `port` **MUST** be set to `587` under the `dot_mail.default.smtp_options.port` key. |
| 63 | +- `tls` **MUST** be set to `STARTTLS` under the `dot_mail.default.smtp_options.tls` key. |
| 64 | +- `host` **MUST** be one of `smtp-mail.outlook.com` or `smtp.office365.com` under the `dot_mail.default.smtp_options.host` key. |
| 65 | + |
| 66 | +## Additional info |
10 | 67 |
|
11 | | -`Dot-mail` configuration **MUST** use the `smtp.office365.com` host under the `dot_mail.default.smtp_options.host` key. |
| 68 | +`dotkernel/dot-mail-outlook` makes use of SASL XOAUTH2 mechanism for use with the [SMTP AUTH](https://datatracker.ietf.org/doc/html/rfc4954) command. |
12 | 69 |
|
13 | | -> Make sure the port is set to 587 |
| 70 | +To allow generating the bearer token in the background, without user input required, |
| 71 | +`dot-mail-outlook` uses the "client credentials" flow from Microsoft: |
14 | 72 |
|
15 | | -`Dot-mail` configuration **MUST** be updated to set `tls` to `STARTTLS` under the `dot_mail.default.smtp_options.tls` key, for the `AUTH XOAUTH` command. |
| 73 | +- [Authenticate an IMAP, POP or SMTP connection using OAuth](https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth) |
| 74 | +- [Microsoft identity platform and the OAuth 2.0 client credentials flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow) |
16 | 75 |
|
17 | | -Register the `ConfigProvider` in `config/config.php`. |
| 76 | +> Make sure to set all relevant permissions, give relevant tenant administrator consent and register the necessary service principals, as described in Microsoft's flow. |
0 commit comments