Add Postmark support as an alternative to SMTP mailing

This commit is contained in:
Celestora 2021-12-27 13:56:25 +02:00
parent 10b2ae82d8
commit 1e45ef5ef7
3 changed files with 996 additions and 237 deletions

View file

@ -3,11 +3,31 @@ namespace Chandler\Email;
use Swift_SmtpTransport; use Swift_SmtpTransport;
use Swift_Message; use Swift_Message;
use Swift_Mailer; use Swift_Mailer;
use Postmark\PostmarkClient;
class Email class Email
{ {
static function send(string $to, string $subject, string $html) static function send(string $to, string $subject, string $html)
{ {
if(isset(CHANDLER_ROOT_CONF["email"]["postmark"])) {
return (new PostmarkClient(CHANDLER_ROOT_CONF["email"]["postmark"]["key"]))->sendEmail(
CHANDLER_ROOT_CONF["email"]["postmark"]["user"],
$to,
$subject,
$html,
strip_tags($html),
NULL,
true,
NULL,
NULL,
NULL,
["Sensitivity" => "Company-Confidential"],
NULL,
"None",
NULL,
CHANDLER_ROOT_CONF["email"]["postmark"]["stream"]
);
} else {
$transport = new Swift_SmtpTransport(CHANDLER_ROOT_CONF["email"]["host"], CHANDLER_ROOT_CONF["email"]["port"], "ssl"); $transport = new Swift_SmtpTransport(CHANDLER_ROOT_CONF["email"]["host"], CHANDLER_ROOT_CONF["email"]["port"], "ssl");
$transport->setUsername(CHANDLER_ROOT_CONF["email"]["addr"]); $transport->setUsername(CHANDLER_ROOT_CONF["email"]["addr"]);
$transport->setPassword(CHANDLER_ROOT_CONF["email"]["pass"]); $transport->setPassword(CHANDLER_ROOT_CONF["email"]["pass"]);
@ -21,4 +41,5 @@ class Email
$mailer = new Swift_Mailer($transport); $mailer = new Swift_Mailer($transport);
return $mailer->send($message); return $mailer->send($message);
} }
}
} }

View file

@ -10,9 +10,11 @@
"nette/safe-stream": "^2.4", "nette/safe-stream": "^2.4",
"nette/tokenizer": "^3.1", "nette/tokenizer": "^3.1",
"firebase/php-jwt": "^5.0", "firebase/php-jwt": "^5.0",
"tracy/tracy": "^2.7",
"symfony/translation": "^5.0", "symfony/translation": "^5.0",
"symfony/yaml": "^5.3" "symfony/yaml": "^5.3",
"guzzlehttp/guzzle": "^6.0",
"wildbit/postmark-php": "^4.0",
"tracy/tracy": "2.9"
}, },
"suggest": { "suggest": {
"ext-yaml": "for faster yaml parsing" "ext-yaml": "for faster yaml parsing"

1176
composer.lock generated

File diff suppressed because it is too large Load diff