Jens Segers on

Laravel SMTP driver vs. API drivers

After Mandrill changed their pricing model, I (as well as many others) started exploring different transactional email services. Laravel only supports a couple providers out of the box, but what about the others?

All Laravel mail drivers are managed by a core TransportManager, but it was a pain in the ass to register custom drivers in your application service provider. I even had to make a pull request to the Laravel framework to make it somewhat possible. Now that the pull request is merged you will be able to register a new mail driver like this:

 public function register()
{
    $this->app['swift.transport']->extend('postmark', function () {
        return new PostmarkTransport($this->app['config']->get('services.postmark.token'));
    });
}

But is it worth it? I mean, almost every email service has support for SMTP, and Laravel has an SMTP driver by default. So why even bother registering a custom email driver?

First I thought it would make a difference in performance. So I did some quick tests on an Ubuntu Vagrant box:

Postmark API driver:
average duration: 0.66 seconds

Postmark SMTP driver:
average duration: 0.36 seconds

Mandrill API driver:
average duration: 0.67 seconds

Mandrill SMTP driver:
average duration: 0.54 seconds

At first sight, the API drivers are not quicker at all. Actually, in my simple test the SMTP driver was faster for both Postmark and Mandrill.

The main takeaway here is that it is fine to just use the SMTP driver rather than spending time on hooking a new API driver into Laravel. Unless you are using specific API features to get message ID's or bulk emails you should be perfectly fine with the default SMTP driver. Let me know in the comments what you think!

Webmentions

Tweet about this blog post and you will appear below!