|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Mail; |
|
4
|
|
|
|
|
5
|
|
|
use Nip\Config\ConfigAwareTrait; |
|
6
|
|
|
use Nip\Mail\Transport\AbstractTransport; |
|
7
|
|
|
use Nip\Mail\Transport\SendgridTransport; |
|
8
|
|
|
use Swift_SmtpTransport as SmtpTransport; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class TransportManager |
|
12
|
|
|
* @package Nip\Mail |
|
13
|
|
|
*/ |
|
14
|
|
|
class TransportManager |
|
15
|
|
|
{ |
|
16
|
|
|
use ConfigAwareTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return AbstractTransport |
|
20
|
|
|
*/ |
|
21
|
1 |
|
public function create() |
|
22
|
|
|
{ |
|
23
|
1 |
|
return $this->createSendgridTransport(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create an instance of the Mailgun Swift Transport driver. |
|
28
|
|
|
* |
|
29
|
|
|
* @return SendgridTransport |
|
30
|
|
|
*/ |
|
31
|
1 |
|
protected function createSendgridTransport() |
|
32
|
|
|
{ |
|
33
|
1 |
|
$config = $this->getConfig(); |
|
34
|
|
|
|
|
35
|
1 |
|
$transport = new SendgridTransport(); |
|
36
|
1 |
|
$transport->setApiKey($config->get('SENDGRID.key')); |
|
37
|
|
|
|
|
38
|
1 |
|
return $transport; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Create an instance of the SMTP Swift Transport driver. |
|
43
|
|
|
* |
|
44
|
|
|
* @return SmtpTransport |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function createSmtpTransport() |
|
47
|
|
|
{ |
|
48
|
|
|
$config = $this->getConfig()->get('mail'); |
|
49
|
|
|
|
|
50
|
|
|
// The Swift SMTP transport instance will allow us to use any SMTP backend |
|
51
|
|
|
// for delivering mail such as Sendgrid, Amazon SES, or a custom server |
|
52
|
|
|
// a developer has available. We will just pass this configured host. |
|
53
|
|
|
$transport = SmtpTransport::newInstance($config['host'], $config['port']); |
|
54
|
|
|
|
|
55
|
|
|
if (isset($config['encryption'])) { |
|
56
|
|
|
$transport->setEncryption($config['encryption']); |
|
57
|
|
|
} |
|
58
|
|
|
// Once we have the transport we will check for the presence of a username |
|
59
|
|
|
// and password. If we have it we will set the credentials on the Swift |
|
60
|
|
|
// transporter instance so that we'll properly authenticate delivery. |
|
61
|
|
|
if (isset($config['username'])) { |
|
62
|
|
|
$transport->setUsername($config['username']); |
|
63
|
|
|
$transport->setPassword($config['password']); |
|
64
|
|
|
} |
|
65
|
|
|
if (isset($config['stream'])) { |
|
66
|
|
|
$transport->setStreamOptions($config['stream']); |
|
67
|
|
|
} |
|
68
|
|
|
return $transport; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|