Completed
Push — master ( fcc3a0...a5af0d )
by Stefano
02:15
created

Ses::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
/**
4
 * Email\SES
5
 *
6
 * Email\SES SMTP driver.
7
 *
8
 * @package core
9
 * @author [email protected]
10
 * @copyright Caffeina srl - 2015 - http://caffeina.it
11
 */
12
13
namespace Email;
14
15
class Ses extends Smtp {
16
17
  public function __construct($options = null) {
18
    $options  = (object)$options;
19
    $region   = isset($options->region) ? $options->region : 'eu-west-1';
20
    if (empty($options->username) || empty($options->password))
21
       throw new \Exception("[Core.Email.SES] You must provide Amazon SES SMTP username and password", 1);
22
23
    Smtp::__construct([
24
      'host'     => "email-smtp.{$region}.amazonaws.com",
25
      'secure'   => true,
26
      'port'     => 465,
27
      'username' => $options->username,
28
      'password' => $options->password,
29
    ]);
30
31
    if (!empty($options->from)) $this->from($options->from);
32
  }
33
34
  public function send(){
35
    if (empty($this->from->full))
36
       throw new \Exception("[Core.Email.SES] Amazon SES needs a registered `from` address", 1);
37
    return Smtp::send();
38
  }
39
40
}
41
42