修复自建邮箱发送错误: INVALID HEADER Missing required header field: "Date"

This commit is contained in:
liyujie 2023-11-24 10:33:14 +08:00
parent 495fc628e4
commit ab33b6571c

View File

@ -6,6 +6,7 @@ import (
"fmt"
"net/smtp"
"strings"
"time"
)
func SendEmail(subject string, receiver string, content string) error {
@ -16,8 +17,9 @@ func SendEmail(subject string, receiver string, content string) error {
mail := []byte(fmt.Sprintf("To: %s\r\n"+
"From: %s<%s>\r\n"+
"Subject: %s\r\n"+
"Date: %s\r\n"+
"Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n",
receiver, SystemName, SMTPFrom, encodedSubject, content))
receiver, SystemName, SMTPFrom, encodedSubject, time.Now().Format(time.RFC1123Z), content))
auth := smtp.PlainAuth("", SMTPAccount, SMTPToken, SMTPServer)
addr := fmt.Sprintf("%s:%d", SMTPServer, SMTPPort)
to := strings.Split(receiver, ";")