mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
@@ -113,7 +113,7 @@ func (a *App) sendNotificationEmail(c request.CTX, notification *PostNotificatio
|
||||
return errors.Wrap(err, "unable to render the email notification template")
|
||||
}
|
||||
|
||||
templateString := "<%s@mattermost.com>"
|
||||
templateString := "<%s@" + utils.GetHostnameFromSiteURL(a.GetSiteURL()) + ">"
|
||||
messageID := ""
|
||||
inReplyTo := ""
|
||||
references := ""
|
||||
|
||||
@@ -6,6 +6,7 @@ package mail
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime"
|
||||
"net"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
gomail "gopkg.in/mail.v2"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
@@ -282,10 +284,10 @@ func sendMailUsingConfigAdvanced(mail mailData, config *SMTPConfig) error {
|
||||
defer c.Quit()
|
||||
defer c.Close()
|
||||
|
||||
return SendMail(c, mail, time.Now())
|
||||
return sendMail(c, mail, time.Now(), config)
|
||||
}
|
||||
|
||||
func SendMail(c smtpClient, mail mailData, date time.Time) error {
|
||||
func sendMail(c smtpClient, mail mailData, date time.Time, config *SMTPConfig) error {
|
||||
mlog.Debug("sending mail", mlog.String("to", mail.smtpTo), mlog.String("subject", mail.subject))
|
||||
|
||||
htmlMessage := mail.htmlBody
|
||||
@@ -315,6 +317,10 @@ func SendMail(c smtpClient, mail mailData, date time.Time) error {
|
||||
|
||||
if mail.messageID != "" {
|
||||
headers["Message-ID"] = []string{mail.messageID}
|
||||
} else {
|
||||
randomStringLength := 16
|
||||
msgID := fmt.Sprintf("<%s-%d@%s>", model.NewRandomString(randomStringLength), time.Now().Unix(), config.Hostname)
|
||||
headers["Message-ID"] = []string{msgID}
|
||||
}
|
||||
|
||||
if mail.inReplyTo != "" {
|
||||
|
||||
@@ -363,13 +363,13 @@ func TestSendMail(t *testing.T) {
|
||||
"\r\nMessage-ID: <abc123@mattermost.com>\r\n",
|
||||
"",
|
||||
},
|
||||
"doesn't add message-id header": {
|
||||
"always adds message-id header": {
|
||||
mail.Address{},
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"\r\nMessage-ID: <",
|
||||
"",
|
||||
"\r\nMessage-ID:",
|
||||
},
|
||||
"adds in-reply-to header": {
|
||||
mail.Address{},
|
||||
@@ -408,7 +408,8 @@ func TestSendMail(t *testing.T) {
|
||||
for testName, tc := range testCases {
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
mail := mailData{"", "", mail.Address{}, "", tc.replyTo, "", "", nil, nil, tc.messageID, tc.inReplyTo, tc.references}
|
||||
err = SendMail(mocm, mail, time.Now())
|
||||
cfg := getConfig()
|
||||
err = sendMail(mocm, mail, time.Now(), cfg)
|
||||
require.NoError(t, err)
|
||||
if tc.contains != "" {
|
||||
require.Contains(t, string(mocm.data), tc.contains)
|
||||
|
||||
Reference in New Issue
Block a user