You can do this by extending the default mail service provider. I was interested in this as well because of the recent news from SparkPost. Basically just copy one of the provider mail transports in to an app folder, such as app/mail/NewTransport.php. Preferably use the transport that best resembles what you are trying to implement. Then create an extended service provider that overrides the register transport function. Then de-register the default mail provider and register your extended one in the app.php config.
Here is my ExtendedMailServiceProvider.php for reference: https://gist.github.com/maxwellimpact/46ded5c553f68946d13d
Read this as well: https://laravel.com/docs/5.0/extending#container-based-extension
Ideally it would be easier to register new transports without having to override the default service provider. Especially with the ever changing landscape of web services. When I get time I may clean up what I've done so far and package it.
I just read a tweet from Taylor on Twitter that the latest 5.2.x release will include a SparkPost mail driver, so save yourself the trouble if thats what you are trying to implement. Hopefully they patch the ability to easily extend the transport as well (or clarify it), but if not the above should still help.
@maxwellimpact, thanks for that info. I'm still running on L5.0 as I'm not fully confident in upgrading without breaking a lot of stuff. The project I'm working on now was built by another dev and I just am not fully up to speed on what all he built. So, I clearly can't update to 5.2.x that has sparkpost built in. I have created that ExtendedMailServiceProvider file as you did in the App\Providers directory but you are including the App\Mail\SparkPostTransport file. Would you be willing to share that file? I hate to waste a lot of time re-inventing the wheel.
Thanks! Andrew
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community