In Laravel 9 the SwiftMailer was deprecated and I'd like to retrieve the message id for email opens, deletes, etc.
Laravel 8 was like so:
public function build()
{
$email = $this->withSwiftMessage(function (Email $message){
[
'message_id' => $message->getId(),
]
});
....
Laravel 9 (attempt)
use Symfony\Component\Mailer\SentMessage;
...
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$email = $this->withSymfonyMessage(function (Email $message){
});
$this->publicMessage->mail()->create(
[
$mailgunWebhook = self::getSymfonyId($email),
]
);
return $this->markdown('emails.public-message-sent')
->from('[email protected]', 'Company name')
->cc('[email protected]', 'Company name')
->subject($this->publicMessage->subject);
}
// On this function I'm getting a mismatched Message, it receives markdown mailable but wants symfony mailable
private function getSymfonyId(SentMessage $sentMessage, $email): string
{
return $email->message_id = $sentMessage->getMessageId();
}
I found this, but I'm not doing a custom implementation.
https://stackoverflow.com/questions/73632087/how-to-get-email-id-when-using-symfony-mailer
Now, https://laravel.com/docs/9.x/mail#headers shows you can do a custom messageId. Is this functionally equivalent to the SymfonyMailer id? Seems like it'd be easier, however, I'm still thinking grabbing Symfony's id is better as it is already being created.
Any thoughts would be great.