-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vitaly Baev
committed
Sep 9, 2016
0 parents
commit 6b1253e
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor | ||
composer.lock | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"laravel/framework": "^5.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Vitalybaev\LaravelDkim; | ||
|
||
use Illuminate\Mail\MailServiceProvider; | ||
|
||
class DkimMailServiceProvider extends MailServiceProvider | ||
{ | ||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
parent::registerSwiftMailer(); | ||
|
||
$this->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; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Vitalybaev\LaravelDkim; | ||
|
||
use Swift_Message; | ||
|
||
class Mailer extends \Illuminate\Mail\Mailer | ||
{ | ||
protected function createMessage() | ||
{ | ||
$message = new Message(new Swift_Message); | ||
|
||
// If a global from address has been specified we will set it on every message | ||
// instances so the developer does not have to repeat themselves every time | ||
// they create a new message. We will just go ahead and push the address. | ||
if (! empty($this->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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Vitalybaev\LaravelDkim; | ||
|
||
use Swift_Signers_DKIMSigner; | ||
|
||
class Message extends \Illuminate\Mail\Message | ||
{ | ||
/** | ||
* @param $selector | ||
* @param $domain | ||
* @param $privateKey | ||
* | ||
* @return $this | ||
*/ | ||
public function attachDkim($selector, $domain, $privateKey) | ||
{ | ||
$signer = new Swift_Signers_DKIMSigner($privateKey, $domain, $selector); | ||
$this->swift->attachSigner($signer); | ||
|
||
return $this; | ||
} | ||
} |