Skip to content

Commit

Permalink
Fix MicrosoftGraphTransport to handle sending from alias (InnoGE#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
naifmhd committed May 2, 2024
1 parent 2336ce2 commit 792f055
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/MicrosoftGraphTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Collection;
use InnoGE\LaravelMsGraphMail\Services\MicrosoftGraphApiService;
use Psr\EventDispatcher\EventDispatcherInterface;
use InnoGE\LaravelMsGraphMail\Exceptions\ConfigurationMissing;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\SentMessage;
Expand Down Expand Up @@ -58,6 +59,12 @@ protected function doSend(SentMessage $message): void
'saveToSentItems' => config('mail.mailers.microsoft-graph.save_to_sent_items', false) ?? false,
];

if(config('mail.mailers.microsoft-graph.send_from_alias', false)) {
$fromAlias = env('MAIL_FROM_ALIAS');
throw_if(empty($fromAlias), new ConfigurationMissing('from.address'));
$payload['from']=$this->transformEmailAddress(new Address($fromAlias));
}

$this->microsoftGraphApiService->sendMail($envelope->getSender()->getAddress(), $payload);
}

Expand Down Expand Up @@ -86,6 +93,7 @@ protected function prepareAttachments(Email $email, ?string $html): array
*/
protected function transformEmailAddresses(Collection $recipients): array
{
info(json_encode($recipients));
return $recipients
->map(fn (Address $recipient) => $this->transformEmailAddress($recipient))
->toArray();
Expand Down

0 comments on commit 792f055

Please sign in to comment.