[Mailer] Add Bcc recipients to sendmail #39744
Conversation
} | ||
} else { | ||
foreach ($message->getEnvelope()->getRecipients() as $recipient) { | ||
$this->stream->write('Bcc:'.$recipient->toString()."\n"); |
jderusse
Jan 6, 2021
Author
Member
I'm not sure this is a good idea.
Basically, if somebody send an email to foo
, the payload sent to sendmail
will contain to: foo
and Bcc: foo
...
Do you have a better idea to find the missing recipients?...
frans-beech-it
Jan 7, 2021
the Bcc
should always be in the $message->getOriginalMessage()->message
so maybe walk through $message->getOriginalMessage()->toIterable()
until you get the Content-Type
header?
But feels hacky
$email = $message->getOriginalMessage(); | ||
if ($email instanceof Email) { | ||
foreach ($email->getBcc() as $recipient) { | ||
$this->stream->write('Bcc:'.$recipient->toString()."\n"); |
jderusse
Jan 6, 2021
Author
Member
Is it allowed to send Bcc:
header BEFORE the rest of the payload?
frans-beech-it
Jan 7, 2021
header now starts with From:
and as Bcc:
is part of the destination fields I don't think that should be a problem https://tools.ietf.org/html/rfc2822#section-3.6.3
But my main concern is that you "fix" this now on this place. But as Bcc
is part of the official RFC for defining mails why is is not just part of the header of the message? And removed on the place where i'ts processed as described in the RFC?
So remove
and adjust the transports that handle the recipients self like smtp
jderusse
Jan 7, 2021
Author
Member
Sendmail and Smtp (and many other transports) send the exact same payload. Reverting this change will affect everybody, it would be BC break, and maybe a security issue.
The question is. Should we re-add the Bcc header for transport that support it?
Or should we remove the Bcc header for transports that does not support it?
In my opinion, the option 1 (the one Symfony is currently using) is safe by default and we should keep that behavior.
Some transports (like Smtp, Sqs) provides alternatives ways to inject the recipients without sending this header.
frans-beech-it
Jan 7, 2021
I get the BC issue. But currently the Mime/Message.php
output is just not following the email specifications
And yes the order transports handle this currently on there own. But IMO the code should try to be as close to the specifications to keep it understandable for others.
The other only "save" way to fix this for the sendMailTransport is to grep the raw message and search for the bcc header but not sure if that will be robust enough.
But adding every recipient as Bcc is not a real solution IMHO
Any status update on this? I've just debugged my app and found out that BCC is completely ignored when using sendmail. It even happens silently so nobody even notices it. |
I second @Toflar 's comment, this took a lot of debugging to figure out that Symfony Mailer is just discarding Bcc recipients. |
When sending an email via
sendmail
with flag-t
, Symfony will send a raw email, and thesendmail
binary will get the recipient list from the message headers. But the BCC header is not removed from the RawEmail on purpose.This PR injects the removed BCC headers.