validate smtp configuration
This commit is contained in:
parent
ab28f08480
commit
5a9f83c43d
3 changed files with 23 additions and 0 deletions
|
@ -524,6 +524,11 @@ return [
|
||||||
'description' => 'The project key has expired. Please generate a new key using the Appwrite console.',
|
'description' => 'The project key has expired. Please generate a new key using the Appwrite console.',
|
||||||
'code' => 401,
|
'code' => 401,
|
||||||
],
|
],
|
||||||
|
Exception::PROJECT_SMTP_CONFIG_INVALID => [
|
||||||
|
'name' => Exception::PROJECT_SMTP_CONFIG_INVALID,
|
||||||
|
'description' => 'Provided SMTP config is invalid.',
|
||||||
|
'code' => 400,
|
||||||
|
],
|
||||||
Exception::PROJECT_TEMPLATE_DEFAULT_DELETION => [
|
Exception::PROJECT_TEMPLATE_DEFAULT_DELETION => [
|
||||||
'name' => Exception::PROJECT_TEMPLATE_DEFAULT_DELETION,
|
'name' => Exception::PROJECT_TEMPLATE_DEFAULT_DELETION,
|
||||||
'description' => 'The default template for the project cannot be deleted.',
|
'description' => 'The default template for the project cannot be deleted.',
|
||||||
|
|
|
@ -39,6 +39,7 @@ use Utopia\Validator\Text;
|
||||||
use Utopia\Validator\WhiteList;
|
use Utopia\Validator\WhiteList;
|
||||||
use Appwrite\Template\Template;
|
use Appwrite\Template\Template;
|
||||||
use Utopia\Locale\Locale;
|
use Utopia\Locale\Locale;
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
App::init()
|
App::init()
|
||||||
->groups(['projects'])
|
->groups(['projects'])
|
||||||
|
@ -1634,6 +1635,21 @@ App::patch('/v1/projects/:projectId/smtp')
|
||||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validate SMTP settings
|
||||||
|
$mail = new PHPMailer(true);
|
||||||
|
$mail->isSMTP();
|
||||||
|
$mail->Username = $username;
|
||||||
|
$mail->Password = $password;
|
||||||
|
$mail->Host = $host;
|
||||||
|
$mail->Port = $port;
|
||||||
|
$mail->SMTPSecure = $secure;
|
||||||
|
$mail->SMTPAutoTLS = false;
|
||||||
|
$valid = $mail->SmtpConnect();
|
||||||
|
|
||||||
|
if(!$valid) {
|
||||||
|
throw new Exception(Exception::GENERAL_SMTP_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
$smtp = [
|
$smtp = [
|
||||||
'enabled' => $enabled,
|
'enabled' => $enabled,
|
||||||
'sender' => $sender,
|
'sender' => $sender,
|
||||||
|
|
|
@ -164,6 +164,8 @@ class Exception extends \Exception
|
||||||
public const PROJECT_RESERVED_PROJECT = 'project_reserved_project';
|
public const PROJECT_RESERVED_PROJECT = 'project_reserved_project';
|
||||||
public const PROJECT_KEY_EXPIRED = 'project_key_expired';
|
public const PROJECT_KEY_EXPIRED = 'project_key_expired';
|
||||||
|
|
||||||
|
public const PROJECT_SMTP_CONFIG_INVALID = 'project_smtp_config_invalid';
|
||||||
|
|
||||||
public const PROJECT_TEMPLATE_DEFAULT_DELETION = 'project_template_default_deletion';
|
public const PROJECT_TEMPLATE_DEFAULT_DELETION = 'project_template_default_deletion';
|
||||||
|
|
||||||
/** Webhooks */
|
/** Webhooks */
|
||||||
|
|
Loading…
Reference in a new issue