1
0
Fork 0
mirror of synced 2024-07-04 14:10:33 +12:00

validate smtp configuration

This commit is contained in:
Damodar Lohani 2023-05-23 05:09:17 +00:00
parent ab28f08480
commit 5a9f83c43d
3 changed files with 23 additions and 0 deletions

View file

@ -524,6 +524,11 @@ return [
'description' => 'The project key has expired. Please generate a new key using the Appwrite console.',
'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 => [
'name' => Exception::PROJECT_TEMPLATE_DEFAULT_DELETION,
'description' => 'The default template for the project cannot be deleted.',

View file

@ -39,6 +39,7 @@ use Utopia\Validator\Text;
use Utopia\Validator\WhiteList;
use Appwrite\Template\Template;
use Utopia\Locale\Locale;
use PHPMailer\PHPMailer\PHPMailer;
App::init()
->groups(['projects'])
@ -1634,6 +1635,21 @@ App::patch('/v1/projects/:projectId/smtp')
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 = [
'enabled' => $enabled,
'sender' => $sender,

View file

@ -164,6 +164,8 @@ class Exception extends \Exception
public const PROJECT_RESERVED_PROJECT = 'project_reserved_project';
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';
/** Webhooks */