Skip to content

Commit

Permalink
fix: add Date header for email (songquanpeng#742)
Browse files Browse the repository at this point in the history
* 修复自建邮箱发送错误: INVALID HEADER Missing required header field: "Date"

* chore: fix style

---------

Co-authored-by: liyujie <[email protected]>
Co-authored-by: JustSong <[email protected]>
Co-authored-by: JustSong <[email protected]>
  • Loading branch information
4 people authored Nov 24, 2023
1 parent b4d67ca commit 923e245
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions common/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/smtp"
"strings"
"time"
)

func SendEmail(subject string, receiver string, content string) error {
Expand All @@ -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, ";")
Expand Down

0 comments on commit 923e245

Please sign in to comment.