Skip to content

Commit

Permalink
[Mailer] [Mailgun] Fix outlook sender
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanavr authored and nicolas-grekas committed Sep 29, 2023
1 parent df371e4 commit 5494941
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Tests/Transport/MailgunApiTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function testCustomHeader()
$deliveryTime = (new \DateTimeImmutable('2020-03-20 13:01:00'))->format(\DateTimeInterface::RFC2822);

$email = new Email();
$envelope = new Envelope(new Address('[email protected]'), [new Address('[email protected]')]);
$email->getHeaders()->addTextHeader('h:sender', $envelope->getSender()->toString());
$email->getHeaders()->addTextHeader('h:X-Mailgun-Variables', $json);
$email->getHeaders()->addTextHeader('h:foo', 'foo-value');
$email->getHeaders()->addTextHeader('t:text', 'text-value');
Expand All @@ -69,7 +71,6 @@ public function testCustomHeader()
$email->getHeaders()->addTextHeader('template', 'template-value');
$email->getHeaders()->addTextHeader('recipient-variables', 'recipient-variables-value');
$email->getHeaders()->addTextHeader('amp-html', 'amp-html-value');
$envelope = new Envelope(new Address('[email protected]'), [new Address('[email protected]')]);

$transport = new MailgunApiTransport('ACCESS_KEY', 'DOMAIN');
$method = new \ReflectionMethod(MailgunApiTransport::class, 'getPayload');
Expand All @@ -78,6 +79,8 @@ public function testCustomHeader()
$this->assertArrayHasKey('h:X-Mailgun-Variables', $payload);
$this->assertEquals($json, $payload['h:X-Mailgun-Variables']);

$this->assertArrayHasKey('h:sender', $payload);
$this->assertEquals($envelope->getSender()->toString(), $payload['h:sender']);
$this->assertArrayHasKey('h:foo', $payload);
$this->assertEquals('foo-value', $payload['h:foo']);
$this->assertArrayHasKey('t:text', $payload);
Expand Down
12 changes: 10 additions & 2 deletions Tests/Transport/MailgunHttpTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function testSend()
$this->assertStringContainsString('Subject: Hello!', $content);
$this->assertStringContainsString('To: Saif Eddin <[email protected]>', $content);
$this->assertStringContainsString('From: Fabien <[email protected]>', $content);
$this->assertStringContainsString('Sender: Senior Fabien Eddin <[email protected]>', $content);
$this->assertStringContainsString('h:sender: "Senior Fabien Eddin" <[email protected]>', $content);
$this->assertStringContainsString('Hello There!', $content);

return new MockResponse(json_encode(['id' => 'foobar']), [
Expand All @@ -79,11 +81,17 @@ public function testSend()
$transport->setPort(8984);

$mail = new Email();
$toAddress = new Address('[email protected]', 'Saif Eddin');
$fromAddress = new Address('[email protected]', 'Fabien');
$senderAddress = new Address('[email protected]', 'Senior Fabien Eddin');
$mail->subject('Hello!')
->to(new Address('[email protected]', 'Saif Eddin'))
->from(new Address('[email protected]', 'Fabien'))
->to($toAddress)
->from($fromAddress)
->sender($senderAddress)
->text('Hello There!');

$mail->getHeaders()->addHeader('h:sender', $mail->getSender()->toString());

$message = $transport->send($mail);

$this->assertSame('foobar', $message->getMessageId());
Expand Down
1 change: 1 addition & 0 deletions Transport/MailgunApiTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
private function getPayload(Email $email, Envelope $envelope): array
{
$headers = $email->getHeaders();
$headers->addHeader('h:sender', $envelope->getSender()->toString());
$html = $email->getHtmlBody();
if (null !== $html && \is_resource($html)) {
if (stream_get_meta_data($html)['seekable'] ?? false) {
Expand Down
1 change: 1 addition & 0 deletions Transport/MailgunHttpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function __toString(): string
protected function doSendHttp(SentMessage $message): ResponseInterface
{
$body = new FormDataPart([
'h:sender' => $message->getEnvelope()->getSender()->toString(),
'to' => implode(',', $this->stringifyAddresses($message->getEnvelope()->getRecipients())),
'message' => new DataPart($message->toString(), 'message.mime'),
]);
Expand Down

0 comments on commit 5494941

Please sign in to comment.