From a5ec11e463edff47569df465a235ee49f1efb16e Mon Sep 17 00:00:00 2001 From: CalciumIon <1808837298@qq.com> Date: Fri, 16 Aug 2024 16:16:38 +0800 Subject: [PATCH] fix: add email missing Message-ID --- common/email.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/email.go b/common/email.go index 62c9048..b23bb23 100644 --- a/common/email.go +++ b/common/email.go @@ -9,6 +9,11 @@ import ( "time" ) +func generateMessageID() string { + domain := strings.Split(SMTPFrom, "@")[1] + return fmt.Sprintf("<%d.%s@%s>", time.Now().UnixNano(), GetRandomString(12), domain) +} + func SendEmail(subject string, receiver string, content string) error { if SMTPFrom == "" { // for compatibility SMTPFrom = SMTPAccount @@ -18,8 +23,9 @@ func SendEmail(subject string, receiver string, content string) error { "From: %s<%s>\r\n"+ "Subject: %s\r\n"+ "Date: %s\r\n"+ + "Message-ID: %s\r\n"+ // 添加 Message-ID 头 "Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n", - receiver, SystemName, SMTPFrom, encodedSubject, time.Now().Format(time.RFC1123Z), content)) + receiver, SystemName, SMTPFrom, encodedSubject, time.Now().Format(time.RFC1123Z), generateMessageID(), content)) auth := smtp.PlainAuth("", SMTPAccount, SMTPToken, SMTPServer) addr := fmt.Sprintf("%s:%d", SMTPServer, SMTPPort) to := strings.Split(receiver, ";")