Convert MailMessage to Mailable in Laravel 5.3+

The Notification system in Laravel 5.3 makes it easy to send a single block of notification content to multiple channels. I ended up using it mainly to send quick action-oriented mails, since I really liked the drop-dead-simple MailMessage builder:

Unfortunately, that works only for the Notification system. Among other things, it makes it difficult if you just want to send an email to an arbitrary email address. Which is where Mailable comes in.

I needed to use Mailable to send out invite emails for Write500, but didn’t want to lose the elegant email template. The solution turns out to be quite simple!

First, publish the email blade views for “modification”:

php artisan vendor:publish --tag=laravel-notifications

Then we’ll use that view to compile our Mailable:

Simple! :)