diff options
Diffstat (limited to 'services/mailer/mailer.go')
-rw-r--r-- | services/mailer/mailer.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go index 4b1492df0b..eac2b15c3c 100644 --- a/services/mailer/mailer.go +++ b/services/mailer/mailer.go @@ -9,6 +9,7 @@ import ( "bytes" "crypto/tls" "fmt" + "hash/fnv" "io" "net" "net/smtp" @@ -67,6 +68,10 @@ func (m *Message) ToMessage() *gomail.Message { msg.SetBody("text/plain", plainBody) msg.AddAlternative("text/html", m.Body) } + + if len(msg.GetHeader("Message-ID")) == 0 { + msg.SetHeader("Message-ID", m.generateAutoMessageID()) + } return msg } @@ -75,6 +80,17 @@ func (m *Message) SetHeader(field string, value ...string) { m.Headers[field] = value } +func (m *Message) generateAutoMessageID() string { + dateMs := m.Date.UnixNano() / 1e6 + h := fnv.New64() + if len(m.To) > 0 { + _, _ = h.Write([]byte(m.To[0])) + } + _, _ = h.Write([]byte(m.Subject)) + _, _ = h.Write([]byte(m.Body)) + return fmt.Sprintf("<autogen-%d-%016x@%s>", dateMs, h.Sum64(), setting.Domain) +} + // NewMessageFrom creates new mail message object with custom From header. func NewMessageFrom(to []string, fromDisplayName, fromAddress, subject, body string) *Message { log.Trace("NewMessageFrom (body):\n%s", body) |