Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/adapter/PhabricatorMailAmazonSESAdapter.php
12256 views
1
<?php
2
3
final class PhabricatorMailAmazonSESAdapter
4
extends PhabricatorMailAdapter {
5
6
const ADAPTERTYPE = 'ses';
7
8
public function getSupportedMessageTypes() {
9
return array(
10
PhabricatorMailEmailMessage::MESSAGETYPE,
11
);
12
}
13
14
protected function validateOptions(array $options) {
15
PhutilTypeSpec::checkMap(
16
$options,
17
array(
18
'access-key' => 'string',
19
'secret-key' => 'string',
20
'region' => 'string',
21
'endpoint' => 'string',
22
));
23
}
24
25
public function newDefaultOptions() {
26
return array(
27
'access-key' => null,
28
'secret-key' => null,
29
'region' => null,
30
'endpoint' => null,
31
);
32
}
33
34
/**
35
* @phutil-external-symbol class PHPMailerLite
36
*/
37
public function sendMessage(PhabricatorMailExternalMessage $message) {
38
$root = phutil_get_library_root('phabricator');
39
$root = dirname($root);
40
require_once $root.'/externals/phpmailer/class.phpmailer-lite.php';
41
42
$mailer = PHPMailerLite::newFromMessage($message);
43
44
$mailer->Mailer = 'amazon-ses';
45
$mailer->customMailer = $this;
46
47
$mailer->Send();
48
}
49
50
public function executeSend($body) {
51
$key = $this->getOption('access-key');
52
53
$secret = $this->getOption('secret-key');
54
$secret = new PhutilOpaqueEnvelope($secret);
55
56
$region = $this->getOption('region');
57
$endpoint = $this->getOption('endpoint');
58
59
$data = array(
60
'Action' => 'SendRawEmail',
61
'RawMessage.Data' => base64_encode($body),
62
);
63
64
$data = phutil_build_http_querystring($data);
65
66
$future = id(new PhabricatorAWSSESFuture())
67
->setAccessKey($key)
68
->setSecretKey($secret)
69
->setRegion($region)
70
->setEndpoint($endpoint)
71
->setHTTPMethod('POST')
72
->setData($data);
73
74
$future->resolve();
75
76
return true;
77
}
78
79
}
80
81