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

Ses   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 6
Bugs 2 Features 1
Metric Value
wmc 6
c 6
b 2
f 1
lcom 0
cbo 2
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onInit() 0 15 4
A onSend() 0 5 2
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