Skip to content

Commit 7a1e3fb

Browse files
bobvandevijverfabpot
authored andcommitted
[Mailer] Add MicrosoftGraph API Transport
1 parent 883a1b4 commit 7a1e3fb

19 files changed

+1029
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,7 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
28872887
MailerBridge\Mailomat\Transport\MailomatTransportFactory::class => 'mailer.transport_factory.mailomat',
28882888
MailerBridge\MailPace\Transport\MailPaceTransportFactory::class => 'mailer.transport_factory.mailpace',
28892889
MailerBridge\Mailchimp\Transport\MandrillTransportFactory::class => 'mailer.transport_factory.mailchimp',
2890+
MailerBridge\MicrosoftGraph\Transport\MicrosoftGraphTransportFactory::class => 'mailer.transport_factory.microsoftgraph',
28902891
MailerBridge\Postal\Transport\PostalTransportFactory::class => 'mailer.transport_factory.postal',
28912892
MailerBridge\Postmark\Transport\PostmarkTransportFactory::class => 'mailer.transport_factory.postmark',
28922893
MailerBridge\Mailtrap\Transport\MailtrapTransportFactory::class => 'mailer.transport_factory.mailtrap',

src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer_transports.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Mailer\Bridge\Mailomat\Transport\MailomatTransportFactory;
2525
use Symfony\Component\Mailer\Bridge\MailPace\Transport\MailPaceTransportFactory;
2626
use Symfony\Component\Mailer\Bridge\Mailtrap\Transport\MailtrapTransportFactory;
27+
use Symfony\Component\Mailer\Bridge\MicrosoftGraph\Transport\MicrosoftGraphTransportFactory;
2728
use Symfony\Component\Mailer\Bridge\Postal\Transport\PostalTransportFactory;
2829
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
2930
use Symfony\Component\Mailer\Bridge\Resend\Transport\ResendTransportFactory;
@@ -60,6 +61,7 @@
6061
'mailjet' => MailjetTransportFactory::class,
6162
'mailomat' => MailomatTransportFactory::class,
6263
'mailpace' => MailPaceTransportFactory::class,
64+
'microsoftgraph' => MicrosoftGraphTransportFactory::class,
6365
'native' => NativeTransportFactory::class,
6466
'null' => NullTransportFactory::class,
6567
'postal' => PostalTransportFactory::class,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.git* export-ignore

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/.github/workflows/close-pull-request.yml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
7.4
5+
---
6+
7+
* Add the bridge
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2025-present Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Microsoft Graph API Mailer
2+
==========================
3+
4+
Provides [Microsoft Graph API Email](https://learn.microsoft.com/en-us/graph/api/user-sendmail) integration for Symfony Mailer.
5+
6+
Prerequisites
7+
-------------
8+
9+
You will need to:
10+
* Register an application in your Microsoft Azure portal,
11+
* Grant this application the Microsoft Graph `Mail.Send` permission,
12+
* Create a secret for that app.
13+
14+
Configuration example
15+
---------------------
16+
17+
```env
18+
# MAILER
19+
MAILER_DSN=microsoftgraph+api://CLIENT_APP_ID:CLIENT_APP_SECRET@default?tenantId=TENANT_ID
20+
```
21+
22+
This will default to `graph.microsoft.com` for the Graph API and `login.microsoftonline.com` for authentication.
23+
24+
If you need to use third parties operated or specific regions Microsoft services (China, US Government, etc.), you can specify the Graph Endpoint and the Auth Endpoint explicitly.
25+
26+
```env
27+
# MAILER e.g. for China
28+
MAILER_DSN=microsoftgraph+api://CLIENT_APP_ID:CLIENT_APP_SECRET@microsoftgraph.chinacloudapi.cn?tenantId=TENANT_ID&authEndpoint=login.partner.microsoftonline.cn
29+
```
30+
31+
The exact URLs can be found in the Microsoft documentation:
32+
* [Graph Endpoints](https://learn.microsoft.com/en-us/graph/deployments#microsoft-graph-and-graph-explorer-service-root-endpoints)
33+
* [Auth Endpoints](https://learn.microsoft.com/en-us/entra/identity-platform/authentication-national-cloud#microsoft-entra-authentication-endpoints)
34+
35+
You can also specify to not save the messages to sent items using the `noSave` parameter:
36+
37+
```env
38+
# MAILER
39+
MAILER_DSN=microsoftgraph+api://CLIENT_APP_ID:CLIENT_APP_SECRET@default?tenantId=TENANT_ID&noSave=true
40+
```
41+
42+
Troubleshooting
43+
---------------
44+
45+
Beware that the sender email address needs to be an address of an account inside your tenant.
46+
47+
Resources
48+
---------
49+
50+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
51+
* [Report issues](https://github.com/symfony/symfony/issues) and
52+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
53+
in the [main Symfony repository](https://github.com/symfony/symfony)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Bridge\MicrosoftGraph\Tests;
13+
14+
use Symfony\Component\HttpClient\MockHttpClient;
15+
use Symfony\Component\Mailer\Bridge\MicrosoftGraph\TokenManager;
16+
17+
class TokenManagerMock extends TokenManager
18+
{
19+
public function __construct()
20+
{
21+
parent::__construct('', '', '', '', '', new MockHttpClient());
22+
}
23+
24+
public function getToken(): string
25+
{
26+
return 'ACCESSTOKEN';
27+
}
28+
}

0 commit comments

Comments
 (0)