-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Description
Symfony version(s) affected
6.3.7
Description
When using the SMTP transport and listending for the SentMessageEvent the SentMessage contains the messageId generated by symfony instead of the messageId that is returned from the SMTP server.
This is because the code for setting the messageId is in the send method here:
symfony/src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php
Lines 150 to 152 in 5f74215
| if ($this->mtaResult && $messageId = $this->parseMessageId($this->mtaResult)) { | |
| $message->setMessageId($messageId); | |
| } |
witch is after the event is sent.
How to reproduce
Send a email using the SMTP transport and listen for the SentMessageEvent. In this event, the messageId is wrong.
<?php
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Mailer\Event\SentMessageEvent;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Email;
require_once 'vendor/autoload.php';
$dispatcher = new EventDispatcher();
$dispatcher->addListener(SentMessageEvent::class, function (SentMessageEvent $event) {
var_dump($event->getMessage()->getMessageId());
});
$transport = Transport::fromDsn('smtps://usr:pw@email-smtp.eu-west-1.amazonaws.com', $dispatcher);
$email = (new Email())
->from('from@example.com')
->to('to@example.com')
->subject('Test')
->text('Testing');
$sentMessage = $transport->send($email);
var_dump($sentMessage->getMessageId()); // This is different from the messageId dumped in the listener!Possible Solution
Move the code for setting messageId into the doSend method?
Additional Context
No response