Differential D19002 Diff 45567 src/applications/metamta/adapter/PhabricatorMailImplementationAmazonSESAdapter.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/adapter/PhabricatorMailImplementationAmazonSESAdapter.php
<?php | <?php | ||||
final class PhabricatorMailImplementationAmazonSESAdapter | final class PhabricatorMailImplementationAmazonSESAdapter | ||||
extends PhabricatorMailImplementationPHPMailerLiteAdapter { | extends PhabricatorMailImplementationPHPMailerLiteAdapter { | ||||
private $message; | private $message; | ||||
private $isHTML; | private $isHTML; | ||||
public function __construct() { | public function prepareForSend() { | ||||
parent::__construct(); | parent::prepareForSend(); | ||||
$this->mailer->Mailer = 'amazon-ses'; | $this->mailer->Mailer = 'amazon-ses'; | ||||
$this->mailer->customMailer = $this; | $this->mailer->customMailer = $this; | ||||
} | } | ||||
public function supportsMessageIDHeader() { | public function supportsMessageIDHeader() { | ||||
// Amazon SES will ignore any Message-ID we provide. | // Amazon SES will ignore any Message-ID we provide. | ||||
return false; | return false; | ||||
} | } | ||||
protected function validateOptions(array $options) { | |||||
PhutilTypeSpec::checkMap( | |||||
$options, | |||||
array( | |||||
'access-key' => 'string', | |||||
'secret-key' => 'string', | |||||
'endpoint' => 'string', | |||||
)); | |||||
} | |||||
public function newDefaultOptions() { | |||||
return array( | |||||
'access-key' => null, | |||||
'secret-key' => null, | |||||
'endpoint' => null, | |||||
); | |||||
} | |||||
public function newLegacyOptions() { | |||||
return array( | |||||
'access-key' => PhabricatorEnv::getEnvConfig('amazon-ses.access-key'), | |||||
'secret-key' => PhabricatorEnv::getEnvConfig('amazon-ses.secret-key'), | |||||
'endpoint' => PhabricatorEnv::getEnvConfig('amazon-ses.endpoint'), | |||||
); | |||||
} | |||||
/** | /** | ||||
* @phutil-external-symbol class SimpleEmailService | * @phutil-external-symbol class SimpleEmailService | ||||
*/ | */ | ||||
public function executeSend($body) { | public function executeSend($body) { | ||||
$key = PhabricatorEnv::getEnvConfig('amazon-ses.access-key'); | $key = $this->getOption('access-key'); | ||||
$secret = PhabricatorEnv::getEnvConfig('amazon-ses.secret-key'); | $secret = $this->getOption('secret-key'); | ||||
$endpoint = PhabricatorEnv::getEnvConfig('amazon-ses.endpoint'); | $endpoint = $this->getOption('endpoint'); | ||||
$root = phutil_get_library_root('phabricator'); | $root = phutil_get_library_root('phabricator'); | ||||
$root = dirname($root); | $root = dirname($root); | ||||
require_once $root.'/externals/amazon-ses/ses.php'; | require_once $root.'/externals/amazon-ses/ses.php'; | ||||
$service = new SimpleEmailService($key, $secret, $endpoint); | $service = new SimpleEmailService($key, $secret, $endpoint); | ||||
$service->enableUseExceptions(true); | $service->enableUseExceptions(true); | ||||
return $service->sendRawEmail($body); | return $service->sendRawEmail($body); | ||||
} | } | ||||
} | } |