How to get email message id within Mailable in Laravel

Laravel Mailables gives us a huge advantage for sending Markdown template messages.

But some times we need to grab the email message id for future tracking, like for webhooks. Here are the code sample of the mailable class’ build() function grabbing the email message id:

public function build() {
    return $this->markdown('markdown.view')
        ->withSwiftMessage(function($message) use (&$message_id) {
            $message_id = $message->getId();


Leave a Reply