Bugfixes, Postgres improved support
This commit is contained in:
@@ -5,6 +5,7 @@ use Api\Parameter\Parameter;
|
||||
use Api\Parameter\StringType;
|
||||
use External\PHPMailer\Exception;
|
||||
use External\PHPMailer\PHPMailer;
|
||||
use Objects\ConnectionData;
|
||||
|
||||
class SendMail extends Request {
|
||||
|
||||
@@ -20,17 +21,39 @@ class SendMail extends Request {
|
||||
$this->isPublic = false;
|
||||
}
|
||||
|
||||
private function getMailConfig() : ?ConnectionData {
|
||||
$req = new \Api\Settings\Get($this->user);
|
||||
$this->success = $req->execute(array("key" => "^mail_"));
|
||||
$this->lastError = $req->getLastError();
|
||||
|
||||
if ($this->success) {
|
||||
$settings = $req->getResult()["settings"];
|
||||
if (!isset($settings["mail_enabled"]) || $settings["mail_enabled"] !== "1") {
|
||||
$this->createError("Mail is not configured yet.");
|
||||
return null;
|
||||
}
|
||||
|
||||
$host = $settings["mail_host"] ?? "localhost";
|
||||
$port = intval($settings["mail_port"] ?? "25");
|
||||
$login = $settings["mail_username"] ?? "";
|
||||
$password = $settings["mail_password"] ?? "";
|
||||
return new ConnectionData($host, $port, $login, $password);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function execute($values = array()) {
|
||||
if(!parent::execute($values)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$mailConfig = $this->user->getConfiguration()->getMail();
|
||||
if (!$mailConfig) {
|
||||
return $this->createError("Mail is not configured yet.");
|
||||
}
|
||||
$mailConfig = $this->getMailConfig();
|
||||
if (!$this->success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$mail = new PHPMailer;
|
||||
$mail->IsSMTP();
|
||||
$mail->setFrom($this->getParam('from'), $this->getParam('fromName'));
|
||||
|
||||
Reference in New Issue
Block a user