Completed
Branch master (1901f0)
by Stefano
02:53
created

Ses::onInit()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 15
rs 9.2
cc 4
eloc 11
nc 4
nop 1
1
<?php
2
3
/**
4
 * Email\SES
5
 *
6
 * Amazon AWS Simple Email Service SMTP driver.
7
 *
8
 * @package core
9
 * @author [email protected]
10
 * @copyright Caffeina srl - 2016 - http://caffeina.com
11
 */
12
13
namespace Email;
14
15
class Ses extends Smtp {
16
17
  public function onInit($options) {
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 an Amazon SES SMTP username and password", 1);
22
23
    Smtp::onInit([
24
      'host'     => "email-smtp.{$region}.amazonaws.com",
25
      'secure'   => true,
26
      'port'     => 465,
27
      'username' => $options->username,
28
      'password' => $options->password,
29
    ]);
30
31
  }
32
33
  public function onSend(Envelope $envelope){
34
    if (!$envelope->from())
35
       throw new \Exception("[core.email.ses] Amazon SES needs a registered `from` address", 1);
36
    return Smtp::onSend($envelope);
37
  }
38
39
}
40
41