From 4e0477af32b992193fc8ae63430b2a95387c5a6b Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 5 Jan 2026 16:43:05 +0530 Subject: [PATCH] add timeout to mailer --- app/init/registers.php | 2 ++ src/Appwrite/Platform/Workers/Mails.php | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/init/registers.php b/app/init/registers.php index be2009449e..1b58c85aa4 100644 --- a/app/init/registers.php +++ b/app/init/registers.php @@ -360,6 +360,8 @@ $register->set('smtp', function () { $mail->SMTPSecure = System::getEnv('_APP_SMTP_SECURE', ''); $mail->SMTPAutoTLS = false; $mail->CharSet = 'UTF-8'; + $mail->Timeout = 10; /* Connection timeout */ + $mail->getSMTPInstance()->Timelimit = 30; /* Timeout for each individual SMTP command (e.g. HELO, EHLO, etc.) */ $from = \urldecode(System::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME . ' Server')); $email = System::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM); diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 01448620f3..b1f17fc648 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -68,7 +68,8 @@ class Mails extends Action throw new Exception('Skipped mail processing. No SMTP configuration has been set.'); } - $log->addTag('type', empty($smtp) ? 'cloud' : 'smtp'); + $type = empty($smtp) ? 'cloud' : 'smtp'; + $log->addTag('type', $type); $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; $hostname = System::getEnv('_APP_CONSOLE_DOMAIN'); @@ -182,6 +183,9 @@ class Mails extends Action try { $mail->send(); } catch (\Throwable $error) { + if ($type === 'smtp') { + throw new Exception('Error sending mail: ' . $error->getMessage(), 401); + } throw new Exception('Error sending mail: ' . $error->getMessage(), 500); } } @@ -209,6 +213,8 @@ class Mails extends Action $mail->SMTPSecure = $smtp['secure']; $mail->SMTPAutoTLS = false; $mail->CharSet = 'UTF-8'; + $mail->Timeout = 10; /* Connection timeout */ + $mail->getSMTPInstance()->Timelimit = 30; /* Timeout for each individual SMTP command (e.g. HELO, EHLO, etc.) */ $mail->setFrom($smtp['senderEmail'], $smtp['senderName']);