# How to add custom Mail Driver to Laravel Tested on Laravel 5.8 Within the source code of laravel 5.8 at this time of writing, we have this following ```php customCreators[$driver] = $callback; return $this; } // the rest of the code... } ``` it means we can easily extend the driver using this manager class! ## Create a MailDriver class In this case I am using OutlookMailDriver, and since i am going to use the extend method from the existing manager, it expects a Closure therefore i make an invocable method that return a function. ```php get('services.outlook', []); return new OutlookTransportManager($config); }; } } ``` >The signature of your invocable may differ from mine ## Create a CustomMailProvider that extend Illuminate\Mail\MailServiceProvider I am going to override the registerSwiftTransport method yet calling its parent first to have it registered its expected Manager then I extend it with my custom Mail Driver. ```php app->extend('swift.transport', function (TransportManager $transport) { $driver = 'outlook'; $callback = new OutlookMailDriver(); $transport->extend($driver, $callback($transport)); return $transport; }); } } ``` ## Create a class that extends Illuminate\Mail\Transport\Transport Since `Illuminate\Mail\Transport\Transport` is an abstract class therefore i need to have `send` method. ```php [ //... App\Providers\CustomMailProvider::class, //Illuminate\Mail\MailServiceProvider::class, // comment this out ], ]; ``` ## Test ```php // somewhere in your route/web.php Route::get('test', function () { Mail::to('test@example.com')->send(new \App\Mail\Test()); }); ```