From 923e24534b4626f667479da4efc9a2867cdeff5a Mon Sep 17 00:00:00 2001 From: Tillman Bailee <51190972+YOMIkio@users.noreply.github.com> Date: Fri, 24 Nov 2023 20:56:53 +0800 Subject: [PATCH] fix: add Date header for email (#742) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复自建邮箱发送错误: INVALID HEADER Missing required header field: "Date" * chore: fix style --------- Co-authored-by: liyujie <29959257@qq.com> Co-authored-by: JustSong <39998050+songquanpeng@users.noreply.github.com> Co-authored-by: JustSong --- common/email.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/email.go b/common/email.go index 7d6963cc..b915f0f9 100644 --- a/common/email.go +++ b/common/email.go @@ -7,6 +7,7 @@ import ( "fmt" "net/smtp" "strings" + "time" ) func SendEmail(subject string, receiver string, content string) error { @@ -33,9 +34,9 @@ func SendEmail(subject string, receiver string, content string) error { "From: %s<%s>\r\n"+ "Subject: %s\r\n"+ "Message-ID: %s\r\n"+ // add Message-ID header to avoid being treated as spam, RFC 5322 + "Date: %s\r\n"+ "Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n", - receiver, SystemName, SMTPFrom, encodedSubject, messageId, content)) - + receiver, SystemName, SMTPFrom, encodedSubject, messageId, time.Now().Format(time.RFC1123Z), content)) auth := smtp.PlainAuth("", SMTPAccount, SMTPToken, SMTPServer) addr := fmt.Sprintf("%s:%d", SMTPServer, SMTPPort) to := strings.Split(receiver, ";")