mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
When sending with Amazon SES, use the AWS sendRawEmail API instead of sendEmail,
so we can send custom headers. Summary: Test Plan: Reviewers: CC:
This commit is contained in:
parent
ed5cddf8d7
commit
8347729fc0
4 changed files with 42 additions and 63 deletions
19
externals/amazon-ses/ses.php
vendored
19
externals/amazon-ses/ses.php
vendored
|
@ -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.
|
||||
*
|
||||
|
|
13
externals/phpmailer/class.phpmailer-lite.php
vendored
13
externals/phpmailer/class.phpmailer-lite.php
vendored
|
@ -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) . '>');
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class PhabricatorMailImplementationPHPMailerLiteAdapter
|
|||
}
|
||||
|
||||
public function setFrom($email) {
|
||||
$this->mailer->SetFrom($email);
|
||||
$this->mailer->SetFrom($email, '', $crazy_side_effects = false);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue