From 6b1253e9651afb6c44301e7f39a0e9b7d2ffe7ea Mon Sep 17 00:00:00 2001 From: Vitaly Baev Date: Fri, 9 Sep 2016 14:51:58 +0300 Subject: [PATCH] Init commit --- .gitignore | 3 +++ composer.json | 14 ++++++++++ src/DkimMailServiceProvider.php | 46 +++++++++++++++++++++++++++++++++ src/Mailer.php | 29 +++++++++++++++++++++ src/Message.php | 23 +++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 src/DkimMailServiceProvider.php create mode 100644 src/Mailer.php create mode 100644 src/Message.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..116f35f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +vendor +composer.lock +.idea \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d63ae5a --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name": "vitalybaev/laravel5-dkim", + "description": "Laravel 5 package for signing outgoing messages with DKIM.", + "license": "MIT", + "authors": [ + { + "name": "Vitaly Baev", + "email": "dj@vitalybaev.ru" + } + ], + "require": { + "laravel/framework": "^5.2" + } +} diff --git a/src/DkimMailServiceProvider.php b/src/DkimMailServiceProvider.php new file mode 100644 index 0000000..9c64f4e --- /dev/null +++ b/src/DkimMailServiceProvider.php @@ -0,0 +1,46 @@ +app->singleton('mailer', function ($app) { + // Once we have create the mailer instance, we will set a container instance + // on the mailer. This allows us to resolve mailer classes via containers + // for maximum testability on said classes instead of passing Closures. + $mailer = new Mailer( + $app['view'], $app['swift.mailer'], $app['events'] + ); + + $this->setMailerDependencies($mailer, $app); + + // If a "from" address is set, we will set it on the mailer so that all mail + // messages sent by the applications will utilize the same "from" address + // on each one, which makes the developer's life a lot more convenient. + $from = $app['config']['mail.from']; + + if (is_array($from) && isset($from['address'])) { + $mailer->alwaysFrom($from['address'], $from['name']); + } + + $to = $app['config']['mail.to']; + + if (is_array($to) && isset($to['address'])) { + $mailer->alwaysTo($to['address'], $to['name']); + } + + return $mailer; + }); + } +} \ No newline at end of file diff --git a/src/Mailer.php b/src/Mailer.php new file mode 100644 index 0000000..95c05f7 --- /dev/null +++ b/src/Mailer.php @@ -0,0 +1,29 @@ +from['address'])) { + $message->from($this->from['address'], $this->from['name']); + } + + if (config('mail.driver') == 'smtp') { + if (config('mail.dkim_selector') && config('mail.dkim_domain') && config('mail.dkim_private_key')) { + $message->attachDkim(config('mail.dkim_selector'), config('mail.dkim_domain'), config('mail.dkim_private_key')); + } + } + + return $message; + } + +} \ No newline at end of file diff --git a/src/Message.php b/src/Message.php new file mode 100644 index 0000000..c41bac2 --- /dev/null +++ b/src/Message.php @@ -0,0 +1,23 @@ +swift->attachSigner($signer); + + return $this; + } +} \ No newline at end of file