|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/Izumi-kun/yii2-spoolmailer |
|
4
|
|
|
* @copyright Copyright (c) 2017 Viktor Khokhryakov |
|
5
|
|
|
* @license http://opensource.org/licenses/BSD-3-Clause |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace izumi\spoolmailer; |
|
9
|
|
|
|
|
10
|
|
|
use izumi\spoolmailer\spools\BaseSpool; |
|
11
|
|
|
use izumi\spoolmailer\spools\FileSpool; |
|
12
|
|
|
use yii\di\Instance; |
|
13
|
|
|
use yii\mail\MessageInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Mailer with spool. |
|
17
|
|
|
* |
|
18
|
|
|
* @method Message|MessageInterface compose($view = null, array $params = []) |
|
19
|
|
|
* @author Viktor Khokhryakov <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Mailer extends \yii\swiftmailer\Mailer |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var string message default class name. |
|
25
|
|
|
*/ |
|
26
|
|
|
public $messageClass = Message::class; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var BaseSpool|string|array |
|
29
|
|
|
*/ |
|
30
|
|
|
public $spoolMailer = [ |
|
31
|
|
|
'class' => FileSpool::class, |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @inheritdoc |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public function init() |
|
38
|
|
|
{ |
|
39
|
1 |
|
parent::init(); |
|
40
|
1 |
|
$this->spoolMailer = Instance::ensure($this->spoolMailer, BaseSpool::class); |
|
41
|
1 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Add the given email message to queue. |
|
45
|
|
|
* This method will log a message about the email being queued. |
|
46
|
|
|
* @param MessageInterface $message email message instance to be queued |
|
47
|
|
|
* @return bool whether the message has been sent successfully |
|
48
|
|
|
*/ |
|
49
|
4 |
|
public function queue($message) |
|
50
|
|
|
{ |
|
51
|
4 |
|
return $this->spoolMailer->send($message); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Sends messages. |
|
56
|
|
|
* @param string[] $failedRecipients an array of failures by-reference |
|
57
|
|
|
* @return int the number of sent emails |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function flushQueue(&$failedRecipients = null) |
|
60
|
|
|
{ |
|
61
|
1 |
|
return $this->spoolMailer->flush($this, $failedRecipients); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|