From a58cac6d5c3e776b6076f1f2ea42c89468a55320 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 29 Apr 2026 18:57:36 +0800 Subject: [PATCH] fix(smtp): update address formatting in SMTP connection functions - Replaced fmt.Sprintf with net.JoinHostPort for constructing the SMTP address in smtpValidateConnection and smtpSendTestEmail functions, improving address handling and ensuring proper formatting. --- openapi/setting/smtp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openapi/setting/smtp.go b/openapi/setting/smtp.go index 5c0a803a..fc71a2e5 100644 --- a/openapi/setting/smtp.go +++ b/openapi/setting/smtp.go @@ -380,7 +380,7 @@ func handleSmtpTest(c *gin.Context) { // --------------------------------------------------------------------------- func smtpValidateConnection(host string, port int, encryption, username, password string) error { - addr := fmt.Sprintf("%s:%d", host, port) + addr := net.JoinHostPort(host, fmt.Sprintf("%d", port)) auth := smtp.PlainAuth("", username, password, host) switch encryption { @@ -443,7 +443,7 @@ func smtpValidateConnection(host string, port int, encryption, username, passwor // --------------------------------------------------------------------------- func smtpSendTestEmail(host string, port int, encryption, username, password, fromName, fromEmail, toEmail string) error { - addr := fmt.Sprintf("%s:%d", host, port) + addr := net.JoinHostPort(host, fmt.Sprintf("%d", port)) subject := "Yao SMTP Test" body := "This is a test email from Yao to verify your SMTP configuration."