Skip to content

[Mailer] Add MicrosoftGraph API Transport #61290

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 12 commits into
base: 7.4
Choose a base branch
from

Conversation

bobvandevijver
Copy link
Contributor

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues Alternative for #60408
License MIT

Add a new Mailer bridge for the Microsoft Graph API, but without adding the complete Microsoft SDK as we're talking about just two HTTP POST requests.

I continued the work done in #60408 and kept the names mentioned there in the composer definition, but this implementation has been made from scratch, is based on the existing Azure Bridge and supports more features such as priority and inline attachments.

@bobvandevijver

This comment was marked as resolved.

@MatTheCat
Copy link
Contributor

Don’t know if it’s related but it looks like you forgot to update registerMailerConfiguration’s $classToServices in the FrameworkExtension:

@bobvandevijver bobvandevijver force-pushed the microsoft-graph-mailer branch from a117a29 to e5100cc Compare July 31, 2025 19:08
@bobvandevijver
Copy link
Contributor Author

@MatTheCat You are today's hero, thank you!

@bobvandevijver bobvandevijver force-pushed the microsoft-graph-mailer branch 2 times, most recently from 00ecd57 to 37f87a2 Compare August 1, 2025 11:24
@bobvandevijver

This comment was marked as outdated.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I trust you've tested this against the real thing :)
Here are some nitpicking

@bobvandevijver bobvandevijver force-pushed the microsoft-graph-mailer branch from d69147f to e9e0276 Compare August 5, 2025 17:55

public function __toString(): string
{
return \sprintf('microsoft+graphapi://%s', $this->graphEndpoint);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return \sprintf('microsoft+graphapi://%s', $this->graphEndpoint);
return \sprintf('microsoftgraph+api://%s', $this->graphEndpoint);

{
public function create(Dsn $dsn): TransportInterface
{
if ('microsoft+graphapi' !== $dsn->getScheme()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ('microsoft+graphapi' !== $dsn->getScheme()) {
if ('microsoftgraph+api' !== $dsn->getScheme()) {

}

if (null === $tenantId = $dsn->getOption('tenantId')) {
throw new IncompleteDsnException("Transport 'microsoft+graphapi' requires the 'tenant' option.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new IncompleteDsnException("Transport 'microsoft+graphapi' requires the 'tenant' option.");
throw new IncompleteDsnException("Transport 'microsoftgraph+api' requires the 'tenant' option.");

}

if (null === $authEndpoint) {
throw new IncompleteDsnException("Transport 'microsoft+graphapi' requires the 'authEndpoint' option when not using the default graph endpoint.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new IncompleteDsnException("Transport 'microsoft+graphapi' requires the 'authEndpoint' option when not using the default graph endpoint.");
throw new IncompleteDsnException("Transport 'microsoftgraph+api' requires the 'authEndpoint' option when not using the default graph endpoint.");


protected function getSupportedSchemes(): array
{
return ['microsoft+graphapi'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ['microsoft+graphapi'];
return ['microsoftgraph+api'];


```env
# MAILER e.g. for China
MAILER_DSN=microsoft+graph://CLIENT_APP_ID:CLIENT_APP_SECRET@microsoftgraph.chinacloudapi.cn?tenantId=TENANT_ID&authEndpoint=login.partner.microsoftonline.cn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MAILER_DSN=microsoft+graph://CLIENT_APP_ID:CLIENT_APP_SECRET@microsoftgraph.chinacloudapi.cn?tenantId=TENANT_ID&authEndpoint=login.partner.microsoftonline.cn
MAILER_DSN=microsoftgraph+api://CLIENT_APP_ID:CLIENT_APP_SECRET@microsoftgraph.chinacloudapi.cn?tenantId=TENANT_ID&authEndpoint=login.partner.microsoftonline.cn


```env
# MAILER
MAILER_DSN=microsoft+graph://CLIENT_APP_ID:CLIENT_APP_SECRET@default?tenantId=TENANT_ID&noSave=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MAILER_DSN=microsoft+graph://CLIENT_APP_ID:CLIENT_APP_SECRET@default?tenantId=TENANT_ID&noSave=true
MAILER_DSN=microsoftgraph+api://CLIENT_APP_ID:CLIENT_APP_SECRET@default?tenantId=TENANT_ID&noSave=true

* Register an application in your Microsoft Azure portal,
* Grant this application the Microsoft Graph `Mail.Send` permission,
* Create a secret for that app.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -0,0 +1,54 @@
Microsoft Graph API Mailer
======================
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
======================
==========================


This will default to `graph.microsoft.com` for the Graph API and `login.microsoftonline.com` for authentication.

If you need to use third parties operated or specific regions Microsoft services (China, US Government, etc.), you can specify Graph Endpoint and Auth Endpoint explicitly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you need to use third parties operated or specific regions Microsoft services (China, US Government, etc.), you can specify Graph Endpoint and Auth Endpoint explicitly.
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy