Differential D19002 Diff 45600 src/applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php
<?php | <?php | ||||
/** | /** | ||||
* Mail adapter that uses SendGrid's web API to deliver email. | * Mail adapter that uses SendGrid's web API to deliver email. | ||||
*/ | */ | ||||
final class PhabricatorMailImplementationSendGridAdapter | final class PhabricatorMailImplementationSendGridAdapter | ||||
extends PhabricatorMailImplementationAdapter { | extends PhabricatorMailImplementationAdapter { | ||||
private $params = array(); | private $params = array(); | ||||
protected function validateOptions(array $options) { | |||||
PhutilTypeSpec::checkMap( | |||||
$options, | |||||
array( | |||||
'api-user' => 'string', | |||||
'api-key' => 'string', | |||||
amckinley: `string|null`, based on the default options. | |||||
Not Done Inline ActionsThe default option values are intentionally not valid in this case, since we can't provide any kind of default for these values: you need to override them and replace them with strings before the mailer works. epriestley: The default option values are intentionally not valid in this case, since we can't provide any… | |||||
)); | |||||
} | |||||
public function newDefaultOptions() { | |||||
return array( | |||||
'api-user' => null, | |||||
'api-key' => null, | |||||
); | |||||
} | |||||
public function newLegacyOptions() { | |||||
return array( | |||||
'api-user' => PhabricatorEnv::getEnvConfig('sendgrid.api-user'), | |||||
'api-key' => PhabricatorEnv::getEnvConfig('sendgrid.api-key'), | |||||
Not Done Inline Actionssendgrid.api-key amckinley: `sendgrid.api-key` | |||||
Not Done Inline ActionsWhoops! I'm planning to go through all these mailers and re-test them with actual production data over the live internet before promoting to stable, it's just a pain to do that so I'm saving it for the end when hopefully I'm mostly done changing things. epriestley: Whoops!
I'm planning to go through all these mailers and re-test them with actual production… | |||||
); | |||||
} | |||||
public function setFrom($email, $name = '') { | public function setFrom($email, $name = '') { | ||||
$this->params['from'] = $email; | $this->params['from'] = $email; | ||||
$this->params['from-name'] = $name; | $this->params['from-name'] = $name; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function addReplyTo($email, $name = '') { | public function addReplyTo($email, $name = '') { | ||||
if (empty($this->params['reply-to'])) { | if (empty($this->params['reply-to'])) { | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | final class PhabricatorMailImplementationSendGridAdapter | ||||
} | } | ||||
public function supportsMessageIDHeader() { | public function supportsMessageIDHeader() { | ||||
return false; | return false; | ||||
} | } | ||||
public function send() { | public function send() { | ||||
$user = PhabricatorEnv::getEnvConfig('sendgrid.api-user'); | $user = $this->getOption('api-user'); | ||||
$key = PhabricatorEnv::getEnvConfig('sendgrid.api-key'); | $key = $this->getOption('api-key'); | ||||
if (!$user || !$key) { | if (!$user || !$key) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
"Configure '%s' and '%s' to use SendGrid for mail delivery.", | "Configure '%s' and '%s' to use SendGrid for mail delivery.", | ||||
'sendgrid.api-user', | 'sendgrid.api-user', | ||||
'sendgrid.api-key')); | 'sendgrid.api-key')); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |
string|null, based on the default options.