-
Notifications
You must be signed in to change notification settings - Fork 10
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
0 parents
commit 06f0013
Showing
5 changed files
with
449 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,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) 2016 [YarCode Agency](http://yarcode.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,38 @@ | ||
# yarcode/yii2-async-mailer | ||
Mailgun mailer implementation for Yii2 | ||
|
||
## Installation | ||
|
||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). | ||
|
||
Either run | ||
|
||
``` | ||
php composer.phar require --prefer-dist yarcode/yii2-mailgun-mailer | ||
``` | ||
|
||
or add | ||
|
||
```json | ||
"yarcode/yii2-mailgun-mailer": "*" | ||
``` | ||
|
||
## Usage | ||
Configure `YarCode\Yii2\Mailgun\Mailer` as your mailer. | ||
``` | ||
'mailer' => [ | ||
'class' => '\YarCode\Yii2\Mailgun\Mailer', | ||
'domain => 'example.org, | ||
'apiKey => 'foobar', | ||
], | ||
``` | ||
Now you can send your emails as usual. | ||
``` | ||
$message = \Yii::$app->mailer->compose() | ||
->setSubject('test subject') | ||
->setFrom('[email protected]') | ||
->setHtmlBody('test body') | ||
->setTo('[email protected]'); | ||
\Yii::$app->mailer->send($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,36 @@ | ||
{ | ||
"name": "yarcode/yii2-mailgun-mailer", | ||
"description": "Mailgun mailer implementation for Yii2", | ||
"type": "yii2-extension", | ||
"keywords": [ | ||
"yii2", | ||
"mailer", | ||
"mailgun", | ||
"email", | ||
"mail", | ||
"api" | ||
], | ||
"homepage": "http://packagist.org/packages/yarcode/yii2-mailgun-mailer", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Alexey Samoylov", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/yarcode/yii2-mailgun-mailer/issues", | ||
"source": "https://github.com/yarcode/yii2-mailgun-mailer" | ||
}, | ||
"require": { | ||
"yiisoft/yii2": "~2", | ||
"mailgun/mailgun-php": "^2.1", | ||
"php-http/guzzle6-adapter": "^1.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"YarCode\\Yii2\\Mailgun\\": "./src" | ||
} | ||
} | ||
} |
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,73 @@ | ||
<?php | ||
/** | ||
* @author Alexey Samoylov <[email protected]> | ||
*/ | ||
namespace YarCode\Yii2\Mailgun; | ||
|
||
use Mailgun\Mailgun; | ||
use yii\base\InvalidConfigException; | ||
use yii\mail\BaseMailer; | ||
|
||
class Mailer extends BaseMailer | ||
{ | ||
/** @var string */ | ||
public $messageClass = Message::class; | ||
/** @var string */ | ||
protected $apiKey; | ||
/** @var string */ | ||
protected $domain; | ||
/** @var Mailgun */ | ||
protected $client; | ||
|
||
/** | ||
* @param string $apiKey | ||
*/ | ||
public function setApiKey($apiKey) | ||
{ | ||
$this->apiKey = $apiKey; | ||
} | ||
|
||
/** | ||
* @param string $domain | ||
*/ | ||
public function setDomain($domain) | ||
{ | ||
$this->domain = $domain; | ||
} | ||
|
||
/** | ||
* @return Mailgun | ||
*/ | ||
public function getClient() | ||
{ | ||
if (empty($this->client)) { | ||
$this->client = $this->createClient(); | ||
} | ||
return $this->client; | ||
} | ||
|
||
/** | ||
* @return Mailgun | ||
* @throws InvalidConfigException | ||
*/ | ||
protected function createClient() | ||
{ | ||
if (empty($this->apiKey) || empty($this->domain)) { | ||
throw new InvalidConfigException('Invalid mailer configuration'); | ||
} | ||
return new Mailgun($this->apiKey); | ||
} | ||
|
||
/** | ||
* @param Message $message | ||
* @inheritdoc | ||
*/ | ||
protected function sendMessage($message) | ||
{ | ||
$this->getClient()->post("{$this->domain}/messages", | ||
$message->getMessageBuilder()->getMessage(), | ||
$message->getMessageBuilder()->getFiles() | ||
); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.