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.
This commit is contained in:
Max 2026-04-29 18:57:36 +08:00
parent bde4442ff6
commit a58cac6d5c

View file

@ -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."