From 93ab68e5c41df64f51668a847ee5aee0573e75f2 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 16 Mar 2019 12:56:44 +0100 Subject: [PATCH] Add drivers for Mailgun, Mandrill, SES (#1169) --- .../core/src/Mail/MailServiceProvider.php | 5 ++- framework/core/src/Mail/MailgunDriver.php | 29 +++++++++++++++ framework/core/src/Mail/MandrillDriver.php | 28 +++++++++++++++ framework/core/src/Mail/SesDriver.php | 35 +++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 framework/core/src/Mail/MailgunDriver.php create mode 100644 framework/core/src/Mail/MandrillDriver.php create mode 100644 framework/core/src/Mail/SesDriver.php diff --git a/framework/core/src/Mail/MailServiceProvider.php b/framework/core/src/Mail/MailServiceProvider.php index f9a0a1804..3b2c3e189 100644 --- a/framework/core/src/Mail/MailServiceProvider.php +++ b/framework/core/src/Mail/MailServiceProvider.php @@ -22,9 +22,12 @@ class MailServiceProvider extends AbstractServiceProvider { $this->app->singleton('mail.supported_drivers', function () { return [ - 'smtp' => SmtpDriver::class, 'mail' => SendmailDriver::class, + 'mailgun' => MailgunDriver::class, + 'mandrill' => MandrillDriver::class, 'log' => LogDriver::class, + 'ses' => SesDriver::class, + 'smtp' => SmtpDriver::class, ]; }); diff --git a/framework/core/src/Mail/MailgunDriver.php b/framework/core/src/Mail/MailgunDriver.php new file mode 100644 index 000000000..a0457bcfc --- /dev/null +++ b/framework/core/src/Mail/MailgunDriver.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Mail; + +use Flarum\Settings\SettingsRepositoryInterface; +use GuzzleHttp\Client; +use Illuminate\Mail\Transport\MailgunTransport; +use Swift_Transport; + +class MailgunDriver implements DriverInterface +{ + public function buildTransport(SettingsRepositoryInterface $settings): Swift_Transport + { + return new MailgunTransport( + new Client(['connect_timeout' => 60]), + $settings->get('mail_mailgun_secret'), + $settings->get('mail_mailgun_domain') + ); + } +} diff --git a/framework/core/src/Mail/MandrillDriver.php b/framework/core/src/Mail/MandrillDriver.php new file mode 100644 index 000000000..8d6127d41 --- /dev/null +++ b/framework/core/src/Mail/MandrillDriver.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Mail; + +use Flarum\Settings\SettingsRepositoryInterface; +use GuzzleHttp\Client; +use Illuminate\Mail\Transport\MandrillTransport; +use Swift_Transport; + +class MandrillDriver implements DriverInterface +{ + public function buildTransport(SettingsRepositoryInterface $settings): Swift_Transport + { + return new MandrillTransport( + new Client(['connect_timeout' => 60]), + $settings->get('mail_mandrill_secret') + ); + } +} diff --git a/framework/core/src/Mail/SesDriver.php b/framework/core/src/Mail/SesDriver.php new file mode 100644 index 000000000..c5a683a9b --- /dev/null +++ b/framework/core/src/Mail/SesDriver.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Mail; + +use Aws\Ses\SesClient; +use Flarum\Settings\SettingsRepositoryInterface; +use Illuminate\Mail\Transport\SesTransport; +use Swift_Transport; + +class SesDriver implements DriverInterface +{ + public function buildTransport(SettingsRepositoryInterface $settings): Swift_Transport + { + $config = [ + 'version' => 'latest', + 'service' => 'email', + 'region' => $settings->get('mail_ses_region'), + 'credentials' => [ + 'key' => $settings->get('mail_ses_key'), + 'secret' => $settings->get('mail_ses_secret'), + ], + ]; + + return new SesTransport(new SesClient($config)); + } +}