Skip to content
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

[9.x] Add X headers when using Mail::alwaysTo #41101

Merged
merged 4 commits into from
Feb 18, 2022
Merged

[9.x] Add X headers when using Mail::alwaysTo #41101

merged 4 commits into from
Feb 18, 2022

Conversation

morrislaptop
Copy link
Contributor

When using Mail::alwaysTo in development environments, the original To, Cc and Bcc are lost. This makes it difficult to determine where the email was going to during testing.

This PR adds the original to, cc and bcc into X-Headers in the email so this information can be retrieved, while still preventing the email being sent to these recipients.

The below screenshot of Helo shows alwaysTo being set, an attempt to send an email with To, Cc, Bcc and the resultant email with the added headers.

image

$this->assertStringContainsString('X-Cc: dries@laravel.com', $sentMessage->toString());
$this->assertStringContainsString('X-Bcc: james@laravel.com', $sentMessage->toString());
$this->assertFalse($recipients->contains('nuno@laravel.com'));
$this->assertFalse($recipients->contains('dries@laravel.com'));
Copy link
Member

Choose a reason for hiding this comment

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

We should be a bit carefully here because we're not actually checking anymore if the CC: and BCC: headers are not present anymore (something the original tests implicitly did). I don't think BCC recipients, for example, are listed in the recipients of an envelope to begin with?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yeah ok i'll add those checks back in, with the specific headers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BCC won't be in the string (but this is tested by checking the list of recipients)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@driesvints Specifically checking for these headers now 👍 Confirmed that the BCC address is normally returned with $sentMessage->getEnvelope()->getRecipients()

@@ -200,6 +200,7 @@ public function testGlobalToIsRespectedOnAllMessages()

$sentMessage = $mailer->send('foo', ['data'], function (Message $message) {
$message->from('hello@laravel.com');
$message->to('nuno@laravel.com');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this for extra measure

@taylorotwell taylorotwell merged commit 18a996f into laravel:9.x Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants