diff --git a/externals/amazon-ses/ses.php b/externals/amazon-ses/ses.php index b405a6de46..ed5b29e558 100644 --- a/externals/amazon-ses/ses.php +++ b/externals/amazon-ses/ses.php @@ -253,6 +253,25 @@ class SimpleEmailService } + public function sendRawEmail($raw) { + $rest = new SimpleEmailServiceRequest($this, 'POST'); + $rest->setParameter('Action', 'SendRawEmail'); + $rest->setParameter('RawMessage.Data', base64_encode($raw)); + + $rest = $rest->getResponse(); + if($rest->error === false && $rest->code !== 200) { + $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); + } + if($rest->error !== false) { + $this->__triggerError('sendRawEmail', $rest->error); + return false; + } + + $response['MessageId'] = (string)$rest->body->SendEmailResult->MessageId; + $response['RequestId'] = (string)$rest->body->ResponseMetadata->RequestId; + return $response; + } + /** * Given a SimpleEmailServiceMessage object, submits the message to the service for sending. * diff --git a/externals/phpmailer/class.phpmailer-lite.php b/externals/phpmailer/class.phpmailer-lite.php index 2b37167b6f..f12a8d5844 100755 --- a/externals/phpmailer/class.phpmailer-lite.php +++ b/externals/phpmailer/class.phpmailer-lite.php @@ -489,6 +489,18 @@ class PHPMailerLite { // Choose the mailer and send through it switch($this->Mailer) { + + case 'amazon-ses': + $toArr = array(); + foreach($this->to as $t) { + $toArr[] = $this->AddrFormat($t); + } + $to = implode(', ', $toArr); + return $this->customMailer->executeSend( + "To: ".$to."\n". + $header. + $body); + case 'sendmail': $sendAction = $this->SendmailSend($header, $body); return $sendAction; @@ -891,7 +903,6 @@ class PHPMailerLite { $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); } $result .= $this->HeaderLine('X-Priority', $this->Priority); - $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.codeworxtech.com)'); if($this->ConfirmReadingTo != '') { $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); diff --git a/src/applications/metamta/adapter/amazonses/PhabricatorMailImplementationAmazonSESAdapter.php b/src/applications/metamta/adapter/amazonses/PhabricatorMailImplementationAmazonSESAdapter.php index aa73909f11..32f3be948c 100644 --- a/src/applications/metamta/adapter/amazonses/PhabricatorMailImplementationAmazonSESAdapter.php +++ b/src/applications/metamta/adapter/amazonses/PhabricatorMailImplementationAmazonSESAdapter.php @@ -17,78 +17,27 @@ */ class PhabricatorMailImplementationAmazonSESAdapter - extends PhabricatorMailImplementationAdapter { + extends PhabricatorMailImplementationPHPMailerLiteAdapter { private $message; private $isHTML; public function __construct() { - $root = phutil_get_library_root('phabricator'); - $root = dirname($root); - require_once $root.'/externals/amazon-ses/ses.php'; - $this->message = newv('SimpleEmailServiceMessage', array()); + parent::__construct(); + $this->mailer->Mailer = 'amazon-ses'; + $this->mailer->customMailer = $this; } - public function setFrom($email) { - $this->message->setFrom($email); - return $this; - } - - public function addReplyTo($email) { - $this->message->addReplyTo($email); - return $this; - } - - public function addTos(array $emails) { - foreach ($emails as $email) { - $this->message->addTo($email); - } - return $this; - } - - public function addCCs(array $emails) { - foreach ($emails as $email) { - $this->message->addCC($email); - } - return $this; - } - - public function addHeader($header_name, $header_value) { - // SES does not currently support custom headers. - return $this; - } - - public function setBody($body) { - $this->body = $body; - return $this; - } - - public function setSubject($subject) { - $this->message->setSubject($subject); - return $this; - } - - public function setIsHTML($is_html) { - $this->isHTML = true; - return $this; - } - - public function hasValidRecipients() { - return true; - } - - public function send() { - if ($this->isHTML) { - $this->message->setMessageFromString($this->body, $this->body); - } else { - $this->message->setMessageFromString($this->body); - } - + public function executeSend($body) { $key = PhabricatorEnv::getEnvConfig('amazon-ses.access-key'); $secret = PhabricatorEnv::getEnvConfig('amazon-ses.secret-key'); + $root = phutil_get_library_root('phabricator'); + $root = dirname($root); + require_once $root.'/externals/amazon-ses/ses.php'; + $service = new SimpleEmailService($key, $secret); - return $service->sendEmail($this->message); + return $service->sendRawEmail($body); } } diff --git a/src/applications/metamta/adapter/phpmailerlite/PhabricatorMailImplementationPHPMailerLiteAdapter.php b/src/applications/metamta/adapter/phpmailerlite/PhabricatorMailImplementationPHPMailerLiteAdapter.php index b7484c01aa..822ee8e32e 100644 --- a/src/applications/metamta/adapter/phpmailerlite/PhabricatorMailImplementationPHPMailerLiteAdapter.php +++ b/src/applications/metamta/adapter/phpmailerlite/PhabricatorMailImplementationPHPMailerLiteAdapter.php @@ -27,7 +27,7 @@ class PhabricatorMailImplementationPHPMailerLiteAdapter } public function setFrom($email) { - $this->mailer->SetFrom($email); + $this->mailer->SetFrom($email, '', $crazy_side_effects = false); return $this; }