I recently upgraded my app to Laravel 5.8 and one of the reasons I did it so soon this time was the mail driver support for Postmark. In case you don't know Postmark, it's a great service that helps a lot with transactional emailing. Postmark has a way of adding a Tag to a message and/or special meta content so you can do interesting stuff with it's API.

But how can we add those to the Mailable flow of Laravel?

I created a trait that looks like this


And then in any Mailable class I only set the "Tag" or "Meta"

// Initial Mailable call
$mailable = new myMailable();
$mailable->setTag('Tag');
$mailable->setMeta(['id'=>123]);
Mail::to('mail@mail.com')->send($mailable);

and of course chain that to the mailable flow by using the Trait:

// Mailable class
class myMailable extends Mailable
{
 use Postmarkable;

    public function build()
    {
        return $this->addPostmarkHeaders()->subject('My subject')->markdown('markdownfile');
    }
}
        

And that's it :-)