|
1
|
|
|
<?php |
|
2
|
|
|
namespace Flipside\Email; |
|
3
|
|
|
|
|
4
|
|
|
require(dirname(__FILE__).'/../vendor/autoload.php'); |
|
5
|
|
|
class AmazonSES extends EmailService |
|
6
|
|
|
{ |
|
7
|
|
|
protected $ses; |
|
8
|
|
|
|
|
9
|
|
|
public function __construct($params) |
|
10
|
|
|
{ |
|
11
|
|
|
$provider = \Aws\Credentials\CredentialProvider::ini('default', $params['ini']); |
|
12
|
|
|
$this->ses = \Aws\Ses\SesClient::factory([ |
|
|
|
|
|
|
13
|
|
|
'version' => 'latest', |
|
14
|
|
|
'region' => 'us-west-2', |
|
15
|
|
|
'credentials' => $provider]); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function canSend() |
|
19
|
|
|
{ |
|
20
|
|
|
$result = $this->ses->getSendQuota(); |
|
21
|
|
|
$result = $result->getAll(); |
|
|
|
|
|
|
22
|
|
|
$res = $result['Max24HourSend'] - $result['SentLast24Hours']; |
|
23
|
|
|
return $res; |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function sendEmail($email) |
|
27
|
|
|
{ |
|
28
|
|
|
$tos = $email->getToAddresses(); |
|
29
|
|
|
if(is_array($tos)) |
|
30
|
|
|
{ |
|
31
|
|
|
foreach($tos as $to) |
|
32
|
|
|
{ |
|
33
|
|
|
if(strstr($to, 'free.fr') !== false) |
|
34
|
|
|
{ |
|
35
|
|
|
die('Spammer abuse filter!'); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
if($email->hasAttachments()) |
|
40
|
|
|
{ |
|
41
|
|
|
//Amazeon sendEmail doesn't support attachments. We need to use sendRawEmail |
|
42
|
|
|
$args = array(); |
|
43
|
|
|
$args['RawMessage'] = array(); |
|
44
|
|
|
$args['RawMessage']['Data'] = $email->getRawMessage(); |
|
45
|
|
|
try { |
|
46
|
|
|
$res = $this->ses->sendRawEmail($args); |
|
47
|
|
|
return $res; |
|
|
|
|
|
|
48
|
|
|
} catch(\Exception $e) { |
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
else |
|
53
|
|
|
{ |
|
54
|
|
|
$args = array(); |
|
55
|
|
|
$args['Source'] = $email->getFromAddress(); |
|
56
|
|
|
$args['Destination'] = array(); |
|
57
|
|
|
$args['Destination']['ToAddresses'] = $email->getToAddresses(); |
|
58
|
|
|
$args['Destination']['CcAddresses'] = $email->getCCAddresses(); |
|
59
|
|
|
$args['Destination']['BccAddresses'] = $email->getBCCAddresses(); |
|
60
|
|
|
$args['Message'] = array(); |
|
61
|
|
|
$args['Message']['Subject'] = array(); |
|
62
|
|
|
$args['Message']['Subject']['Data'] = $email->getSubject(); |
|
63
|
|
|
$args['Message']['Body'] = array(); |
|
64
|
|
|
$args['Message']['Body']['Text'] = array(); |
|
65
|
|
|
$args['Message']['Body']['Html'] = array(); |
|
66
|
|
|
$args['Message']['Body']['Text']['Data'] = $email->getTextBody(); |
|
67
|
|
|
$args['Message']['Body']['Html']['Data'] = $email->getHtmlBody(); |
|
68
|
|
|
$args['ReplyToAddresses'] = array($email->getReplyTo()); |
|
69
|
|
|
try { |
|
70
|
|
|
return $this->ses->sendEmail($args); |
|
|
|
|
|
|
71
|
|
|
} catch(\Exception $e) { |
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
|
78
|
|
|
|
This method has been deprecated.