1
|
|
|
<?php |
2
|
|
|
namespace 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
|
|
|
//$credentials = \Aws\Common\Credentials\Credentials::fromIni('default', $params['ini']); |
|
|
|
|
13
|
|
|
|
14
|
|
|
$this->ses = \Aws\Ses\SesClient::factory([ |
|
|
|
|
15
|
|
|
'version' => 'latest', |
16
|
|
|
'region' => 'us-west-2', |
17
|
|
|
'credentials' => $provider]); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function canSend() |
21
|
|
|
{ |
22
|
|
|
$result = $this->ses->getSendQuota(); |
23
|
|
|
$result = $result->getAll(); |
|
|
|
|
24
|
|
|
$res = $result['Max24HourSend'] - $result['SentLast24Hours']; |
25
|
|
|
return $res; |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function sendEmail($email) |
29
|
|
|
{ |
30
|
|
|
$tos = $email->getToAddresses(); |
31
|
|
|
if(is_array($tos)) |
32
|
|
|
{ |
33
|
|
|
foreach($tos as $to) |
34
|
|
|
{ |
35
|
|
|
if(strstr($to, 'free.fr') !== false) |
36
|
|
|
{ |
37
|
|
|
die('Spammer abuse filter!'); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if($email->hasAttachments()) |
43
|
|
|
{ |
44
|
|
|
//Amazeon sendEmail doesn't support attachments. We need to use sendRawEmail |
45
|
|
|
$args = array(); |
46
|
|
|
$args['RawMessage'] = array(); |
47
|
|
|
$args['RawMessage']['Data'] = base64_encode($email->getRawMessage()); |
48
|
|
|
try { |
49
|
|
|
return $this->ses->sendRawEmail($args); |
|
|
|
|
50
|
|
|
} catch(\Exception $e) { |
51
|
|
|
return false; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
else |
55
|
|
|
{ |
56
|
|
|
$args = array(); |
57
|
|
|
$args['Source'] = $email->getFromAddress(); |
58
|
|
|
$args['Destination'] = array(); |
59
|
|
|
$args['Destination']['ToAddresses'] = $email->getToAddresses(); |
60
|
|
|
$args['Destination']['CcAddresses'] = $email->getCCAddresses(); |
61
|
|
|
$args['Destination']['BccAddresses'] = $email->getBCCAddresses(); |
62
|
|
|
$args['Message'] = array(); |
63
|
|
|
$args['Message']['Subject'] = array(); |
64
|
|
|
$args['Message']['Subject']['Data'] = $email->getSubject(); |
65
|
|
|
$args['Message']['Body'] = array(); |
66
|
|
|
$args['Message']['Body']['Text'] = array(); |
67
|
|
|
$args['Message']['Body']['Html'] = array(); |
68
|
|
|
$args['Message']['Body']['Text']['Data'] = $email->getTextBody(); |
69
|
|
|
$args['Message']['Body']['Html']['Data'] = $email->getHtmlBody(); |
70
|
|
|
$args['ReplyToAddresses'] = array($email->getReplyTo()); |
71
|
|
|
try { |
72
|
|
|
return $this->ses->sendEmail($args); |
|
|
|
|
73
|
|
|
} catch(\Exception $e) { |
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
80
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.