-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] Add MSGraph API Transport #52546
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
[Mailer] Add MSGraph API Transport #52546
Conversation
Hey! Thanks for your PR. You are targeting branch "5.4" but it seems your PR description refers to branch "6.4 for features". Cheers! Carsonbot |
It looks like you unchecked the "Allow edits from maintainer" box. That is fine, but please note that if you have multiple commits, you'll need to squash your commits into one before this can be merged. Or, you can check the "Allow edits from maintainers" box and the maintainer can squash for you. Cheers! Carsonbot |
d71c385
to
5dd6b58
Compare
This cannot go in the 6.4 branch (nor 7.0 btw). We are 1.5 month after the feature freeze. |
@stof sorry, this is my first contrib. What should I do then ? |
@nguyenk the 7.1 branch is not yet created to open it to contributions, because we would prefer the community to focus on stabilizing the current beta versions. We create the next branch only once the RC versions are released. So you will need to rebase your work once that happens. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR also misses the registration of the new bridge in FrameworkBundle and in \Symfony\Component\Mailer\Transport::FACTORY_CLASSES
to make it usable through the DSN system.
namespace Symfony\Component\Mailer\Bridge\MicrosoftGraph\Transport; | ||
|
||
use GuzzleHttp\Psr7\Stream; | ||
use GuzzleHttp\Psr7\Utils; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using guzzle/psr7 without depending on it is a no-go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it looks like the microsoft graph SDK supports any PSR-7 stream, the transport should rather take a StreamFactory in its constructor.
$tokenRequestContext = new ClientCredentialContext( | ||
$this->tenantId, | ||
$this->clientId, | ||
$this->clientSecret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those properties used elsewhere than here ? If no, they should not be properties at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I'm wondering whether we should really take those scalars here vs injecting directly the actual dependencies (when using the factory, the instantiation would happen there). This would be more consistent with the way other bridges with dependencies are implemented (see the amazon bridge for instance)
$message->setSubject($source->getSubject() ?? 'No subject'); | ||
$itemBody = new ItemBody(); | ||
$itemBody->setContent((string) $source->getHtmlBody()); | ||
$itemBody->setContentType(new BodyType(BodyType::HTML)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic looks broken in case the Email only has a plaintext body.
use Microsoft\Graph\Generated\Models\Recipient; | ||
use Microsoft\Graph\Generated\Users\Item\SendMail\SendMailPostRequestBody; | ||
use Microsoft\Graph\GraphServiceClient; | ||
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you instantiate this class directly which comes from a different package, you should depend on it explicitly instead of relying on the transitive dependency in the microsoft SDK to avoid issues if new major versions are done.
throw new InvalidArgumentException(sprintf("Transport 'microsoft+graph' one of these hosts : '%s'", implode(', ', self::CLOUD_MAP))); | ||
} | ||
|
||
// This parses the MAILER_DSN containing Microsoft Graph API credentials |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment looks wrong to me.
"require": { | ||
"php": ">=8.1", | ||
"symfony/mailer": "^5.4|^6.4|^7.0", | ||
"thecodingmachine/safe": "^2.5.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this dependency ?
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks wrong to me, given that our testsuite does not use PHPUnit 10 yet (as our tooling is not yet compatible with it)
private readonly string $tenantId, | ||
private readonly string $clientId, | ||
private readonly string $clientSecret, | ||
private readonly CacheInterface $cache, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this cache looks unused.
Thank you a lot for you feedback @stof I will have a close look ASAP. Cheers |
Hello, this is kind of related, I opened a PR #54013 for a new component proposal which is about managing access tokens (OAuth2, and possibly some others). I think this might interest you @nguyenk since Microsoft access tokens are OAuth2 tokens. I created this PR after I tried to implement connection to Office 365 / Outlook with the SMTP component, and really think it would worth it to share/aggregate our respective work and patches in order to move in the direction to a more generic, user configurable and re-usable solution. @stof I know that you are a meticulous, attentive reviewer, I'd very much appreciate your sentiments about this PR as well. Thanks in advance to all of you. |
@nguyenk This seems like a pretty promising bridge! This is also a friendly ping to see how things are going and if you need any help :) |
Hello @pounard thank you for the hint. I would definitively look into this PR and use it once (I hope) it's merged. BTW, big 🆙 for you're work on that 👏 |
Thanks ! It seems it's hard to get traction from core team when you don't have a name in the community, so any help for pushing it forward would be great. |
Hi, as we are currently in feature freeze for 7.1 there is not so much attention on following topics, sorry for that. |
any news regarding this? will it be in 7.2 or 7.3? |
Are there any news regarding this PR? |
Feel free to take over and finish this PR 👍🏻 |
If this is ok for @nguyenk I could have a look at it? |
@creiner thanks for asking. Please do, it's been too long I didn't make any move on this one. Thank you. |
closing here as the PR looks stalled, feel free to reopen when you have time to finish it |
I implemented the comments and opened a new PR #60408 for continuing the work. |
This PR is initially comes from #48888 : Microsoft now forces OAuth for sending emails in SMTP which does not seem possible with the current mailer implementation.
I created a gist for a workaround
And I ended up proposing this PR after @xabbuh proposed
This is a Microsoft Graph API implementation, not an SMTP based.