Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/adapter/PhabricatorMailAmazonSESAdapter.php
Show All 11 Lines | final class PhabricatorMailAmazonSESAdapter | ||||
} | } | ||||
protected function validateOptions(array $options) { | protected function validateOptions(array $options) { | ||||
PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
$options, | $options, | ||||
array( | array( | ||||
'access-key' => 'string', | 'access-key' => 'string', | ||||
'secret-key' => 'string', | 'secret-key' => 'string', | ||||
'region' => 'string', | |||||
'endpoint' => 'string', | 'endpoint' => 'string', | ||||
)); | )); | ||||
} | } | ||||
public function newDefaultOptions() { | public function newDefaultOptions() { | ||||
return array( | return array( | ||||
'access-key' => null, | 'access-key' => null, | ||||
'secret-key' => null, | 'secret-key' => null, | ||||
'region' => null, | |||||
'endpoint' => null, | 'endpoint' => null, | ||||
); | ); | ||||
} | } | ||||
/** | /** | ||||
* @phutil-external-symbol class PHPMailerLite | * @phutil-external-symbol class PHPMailerLite | ||||
*/ | */ | ||||
public function sendMessage(PhabricatorMailExternalMessage $message) { | public function sendMessage(PhabricatorMailExternalMessage $message) { | ||||
$root = phutil_get_library_root('phabricator'); | $root = phutil_get_library_root('phabricator'); | ||||
$root = dirname($root); | $root = dirname($root); | ||||
require_once $root.'/externals/phpmailer/class.phpmailer-lite.php'; | require_once $root.'/externals/phpmailer/class.phpmailer-lite.php'; | ||||
$mailer = PHPMailerLite::newFromMessage($message); | $mailer = PHPMailerLite::newFromMessage($message); | ||||
$mailer->Mailer = 'amazon-ses'; | $mailer->Mailer = 'amazon-ses'; | ||||
$mailer->customMailer = $this; | $mailer->customMailer = $this; | ||||
$mailer->Send(); | $mailer->Send(); | ||||
} | } | ||||
/** | |||||
* @phutil-external-symbol class SimpleEmailService | |||||
*/ | |||||
public function executeSend($body) { | public function executeSend($body) { | ||||
$key = $this->getOption('access-key'); | $key = $this->getOption('access-key'); | ||||
$secret = $this->getOption('secret-key'); | $secret = $this->getOption('secret-key'); | ||||
$secret = new PhutilOpaqueEnvelope($secret); | |||||
$region = $this->getOption('region'); | |||||
$endpoint = $this->getOption('endpoint'); | $endpoint = $this->getOption('endpoint'); | ||||
$root = phutil_get_library_root('phabricator'); | $data = array( | ||||
$root = dirname($root); | 'Action' => 'SendRawEmail', | ||||
require_once $root.'/externals/amazon-ses/ses.php'; | 'RawMessage.Data' => base64_encode($body), | ||||
); | |||||
$data = phutil_build_http_querystring($data); | |||||
$future = id(new PhabricatorAWSSESFuture()) | |||||
->setAccessKey($key) | |||||
->setSecretKey($secret) | |||||
->setRegion($region) | |||||
->setEndpoint($endpoint) | |||||
->setHTTPMethod('POST') | |||||
->setData($data); | |||||
$future->resolve(); | |||||
$service = new SimpleEmailService($key, $secret, $endpoint); | return true; | ||||
$service->enableUseExceptions(true); | |||||
return $service->sendRawEmail($body); | |||||
} | } | ||||
} | } |