Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Mailer] Add MSGraph API Transport#60408
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
creiner wants to merge13 commits intosymfony:7.4Choose a base branch fromcreiner:pr/52546
base:7.4
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes from1 commit
Commits
Show all changes
13 commits Select commitHold shift + click to select a range
5388c84
initial commit
nguyenk5dd6b58
fix CI
nguyenke086c8f
Improved MicrosoftGraphMailer after comments
creiner1d03214
Added MicrosoftGraphTransportFactory to the mailer transports
creiner2c0d2e9
fixed ci
creinerecb1f3f
second round of ci fixes
creiner383a1dc
Removed empty line
creiner45ab92c
Removed declare strict types
creiner3d09740
fixed readme and changelog
creinercc44482
removed ms-graph from main composer.json
creiner17d2660
Apply suggestions from code review
creiner4908410
Removed readonly
creinerf1857f8
Improved error handling
creinerFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Improved MicrosoftGraphMailer after comments
- added mail text body handling- removed unused properties- added composer deps
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commite086c8f99a649fd5654b6bbe2fc39be9225d545d
There are no files selected for viewing
16 changes: 9 additions & 7 deletions...onent/Mailer/Bridge/MicrosoftGraph/Tests/Transport/MicrosoftGraphTransportFactoryTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
43 changes: 20 additions & 23 deletionssrc/Symfony/Component/Mailer/Bridge/MicrosoftGraph/Transport/MicrosoftGraphTransport.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -35,33 +35,24 @@ | ||
use Symfony\Component\Mime\Header\ParameterizedHeader; | ||
use Symfony\Component\Mime\Part\DataPart; | ||
use Symfony\Component\Mime\RawMessage; | ||
class MicrosoftGraphTransport implements TransportInterface | ||
{ | ||
private GraphServiceClient $graphServiceClient; | ||
public function __construct( | ||
readonly string $nationalCloud, | ||
readonly ClientCredentialContext $clientCredentialContext, | ||
creiner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
) { | ||
$this->graphServiceClient = new GraphServiceClient($clientCredentialContext, [], $this->nationalCloud); | ||
} | ||
public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage | ||
{ | ||
$envelope = null !== $envelope ? clone $envelope : Envelope::create($message); | ||
if (!$message instanceof Email) { | ||
throw newSendMailException(sprintf("This mailer can only handle mails of class '%s' or it's subclasses, instance of %s passed", Email::class, $message::class)); | ||
} | ||
$this->sendMail($message); | ||
@@ -93,12 +84,12 @@ private function convertEmailToGraphMessage(Email $source): Message | ||
// From | ||
if (0 === \count($source->getFrom())) { | ||
throw newSendMailException("Cannot send mail without 'From'"); | ||
} | ||
$message->setFrom(self::convertAddressToGraphRecipient($source->getFrom()[0])); | ||
//To | ||
$message->setToRecipients(array_map( | ||
static fn (Address $address) => self::convertAddressToGraphRecipient($address), | ||
$source->getTo() | ||
@@ -117,12 +108,18 @@ private function convertEmailToGraphMessage(Email $source): Message | ||
)); | ||
// Subject & body | ||
$message->setSubject($source->getSubject() ?? ''); | ||
$itemBody = new ItemBody(); | ||
if ($source->getHtmlBody()) { | ||
$itemBody->setContent((string) $source->getHtmlBody()); | ||
$itemBody->setContentType(new BodyType(BodyType::HTML)); | ||
} else { | ||
$itemBody->setContent((string) $source->getTextBody()); | ||
$itemBody->setContentType(new BodyType(BodyType::TEXT)); | ||
} | ||
$message->setBody($itemBody); | ||
$message->setAttachments(array_map( | ||
static fn (DataPart $attachment) => self::convertAttachmentGraphAttachment($attachment), | ||
$source->getAttachments() | ||
@@ -153,10 +150,10 @@ private static function convertAttachmentGraphAttachment(DataPart $source): File | ||
$fileStream = Utils::streamFor($source->bodyToString()); | ||
\assert($fileStream instanceof Stream); | ||
$attachment->setContentBytes($fileStream); | ||
$attachment->setContentType($source->getMediaType().'/'.$source->getMediaSubtype()); | ||
$attachment->setName($filename); | ||
$attachment->setODataType('#microsoft.graph.fileAttachment'); | ||
return $attachment; | ||
} | ||
18 changes: 6 additions & 12 deletions...mfony/Component/Mailer/Bridge/MicrosoftGraph/Transport/MicrosoftGraphTransportFactory.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletionssrc/Symfony/Component/Mailer/Bridge/MicrosoftGraph/composer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionsrc/Symfony/Component/Mailer/Bridge/MicrosoftGraph/phpunit.xml.dist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.