Adds configuration for separate reply-to email header. (#10144)
* Adds configuration for separate reply-to email header. * Changes config setting name. * Using a separate variable and value in test. * Updates for config pointer changes in another PR. * Adds new key to test config. Adds default value.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ba7ab0b8d1
Коммит
afcb224a79
@@ -426,6 +426,7 @@ func TestEmailTest(t *testing.T) {
|
||||
SMTPPassword: model.NewString(""),
|
||||
FeedbackName: model.NewString(""),
|
||||
FeedbackEmail: model.NewString(""),
|
||||
ReplyToAddress: model.NewString(""),
|
||||
SendEmailNotifications: model.NewBool(false),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -389,6 +389,7 @@ func (a *App) trackConfig() {
|
||||
"enable_preview_mode_banner": *cfg.EmailSettings.EnablePreviewModeBanner,
|
||||
"isdefault_feedback_name": isDefault(cfg.EmailSettings.FeedbackName, ""),
|
||||
"isdefault_feedback_email": isDefault(cfg.EmailSettings.FeedbackEmail, ""),
|
||||
"isdefault_reply_to_address": isDefault(cfg.EmailSettings.ReplyToAddress, ""),
|
||||
"isdefault_feedback_organization": isDefault(*cfg.EmailSettings.FeedbackOrganization, model.EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION),
|
||||
"skip_server_certificate_verification": *cfg.EmailSettings.SkipServerCertificateVerification,
|
||||
"isdefault_login_button_color": isDefault(*cfg.EmailSettings.LoginButtonColor, ""),
|
||||
|
||||
@@ -44,6 +44,7 @@ package:
|
||||
@# Reset email sending to original configuration
|
||||
sed -i'' -e 's|"SendEmailNotifications": true,|"SendEmailNotifications": false,|g' $(DIST_PATH)/config/config.json
|
||||
sed -i'' -e 's|"FeedbackEmail": "test@example.com",|"FeedbackEmail": "",|g' $(DIST_PATH)/config/config.json
|
||||
sed -i'' -e 's|"ReplyToAddress": "test@example.com",|"ReplyToAddress": "",|g' $(DIST_PATH)/config/config.json
|
||||
sed -i'' -e 's|"SMTPServer": "dockerhost",|"SMTPServer": "",|g' $(DIST_PATH)/config/config.json
|
||||
sed -i'' -e 's|"SMTPPort": "2500",|"SMTPPort": "",|g' $(DIST_PATH)/config/config.json
|
||||
|
||||
|
||||
@@ -181,6 +181,7 @@
|
||||
"RequireEmailVerification": false,
|
||||
"FeedbackName": "",
|
||||
"FeedbackEmail": "test@example.com",
|
||||
"ReplyToAddress": "test@example.com",
|
||||
"FeedbackOrganization": "",
|
||||
"EnableSMTPAuth": false,
|
||||
"SMTPUsername": "",
|
||||
|
||||
@@ -1020,6 +1020,7 @@ type EmailSettings struct {
|
||||
RequireEmailVerification *bool
|
||||
FeedbackName *string
|
||||
FeedbackEmail *string
|
||||
ReplyToAddress *string
|
||||
FeedbackOrganization *string
|
||||
EnableSMTPAuth *bool
|
||||
SMTPUsername *string
|
||||
@@ -1075,6 +1076,10 @@ func (s *EmailSettings) SetDefaults() {
|
||||
s.FeedbackEmail = NewString("test@example.com")
|
||||
}
|
||||
|
||||
if s.ReplyToAddress == nil {
|
||||
s.ReplyToAddress = NewString("test@example.com")
|
||||
}
|
||||
|
||||
if s.FeedbackOrganization == nil {
|
||||
s.FeedbackOrganization = NewString(EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION)
|
||||
}
|
||||
|
||||
@@ -199,12 +199,13 @@ func TestConnection(config *model.Config) {
|
||||
|
||||
func SendMailUsingConfig(to, subject, htmlBody string, config *model.Config, enableComplianceFeatures bool) *model.AppError {
|
||||
fromMail := mail.Address{Name: *config.EmailSettings.FeedbackName, Address: *config.EmailSettings.FeedbackEmail}
|
||||
replyTo := mail.Address{Name: *config.EmailSettings.FeedbackName, Address: *config.EmailSettings.ReplyToAddress}
|
||||
|
||||
return SendMailUsingConfigAdvanced(to, to, fromMail, subject, htmlBody, nil, nil, config, enableComplianceFeatures)
|
||||
return SendMailUsingConfigAdvanced(to, to, fromMail, replyTo, subject, htmlBody, nil, nil, config, enableComplianceFeatures)
|
||||
}
|
||||
|
||||
// allows for sending an email with attachments and differing MIME/SMTP recipients
|
||||
func SendMailUsingConfigAdvanced(mimeTo, smtpTo string, from mail.Address, subject, htmlBody string, attachments []*model.FileInfo, mimeHeaders map[string]string, config *model.Config, enableComplianceFeatures bool) *model.AppError {
|
||||
func SendMailUsingConfigAdvanced(mimeTo, smtpTo string, from, replyTo mail.Address, subject, htmlBody string, attachments []*model.FileInfo, mimeHeaders map[string]string, config *model.Config, enableComplianceFeatures bool) *model.AppError {
|
||||
if !*config.EmailSettings.SendEmailNotifications || len(*config.EmailSettings.SMTPServer) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -227,10 +228,10 @@ func SendMailUsingConfigAdvanced(mimeTo, smtpTo string, from mail.Address, subje
|
||||
return err
|
||||
}
|
||||
|
||||
return SendMail(c, mimeTo, smtpTo, from, subject, htmlBody, attachments, mimeHeaders, fileBackend, time.Now())
|
||||
return SendMail(c, mimeTo, smtpTo, from, replyTo, subject, htmlBody, attachments, mimeHeaders, fileBackend, time.Now())
|
||||
}
|
||||
|
||||
func SendMail(c *smtp.Client, mimeTo, smtpTo string, from mail.Address, subject, htmlBody string, attachments []*model.FileInfo, mimeHeaders map[string]string, fileBackend filesstore.FileBackend, date time.Time) *model.AppError {
|
||||
func SendMail(c *smtp.Client, mimeTo, smtpTo string, from, replyTo mail.Address, subject, htmlBody string, attachments []*model.FileInfo, mimeHeaders map[string]string, fileBackend filesstore.FileBackend, date time.Time) *model.AppError {
|
||||
mlog.Debug(fmt.Sprintf("sending mail to %v with subject of '%v'", smtpTo, subject))
|
||||
|
||||
htmlMessage := "\r\n<html><body>" + htmlBody + "</body></html>"
|
||||
@@ -243,6 +244,7 @@ func SendMail(c *smtp.Client, mimeTo, smtpTo string, from mail.Address, subject,
|
||||
|
||||
headers := map[string][]string{
|
||||
"From": {from.String()},
|
||||
"Reply-To": {replyTo.String()},
|
||||
"To": {mimeTo},
|
||||
"Subject": {encodeRFC2047Word(subject)},
|
||||
"Content-Transfer-Encoding": {"8bit"},
|
||||
|
||||
@@ -142,6 +142,7 @@ func TestSendMailUsingConfigAdvanced(t *testing.T) {
|
||||
var mimeTo = "test@example.com"
|
||||
var smtpTo = "test2@example.com"
|
||||
var from = mail.Address{Name: "Nobody", Address: "nobody@mattermost.com"}
|
||||
var replyTo = mail.Address{Name: "ReplyTo", Address: "reply_to@mattermost.com"}
|
||||
var emailSubject = "Testing this email"
|
||||
var emailBody = "This is a test from autobot"
|
||||
|
||||
@@ -177,7 +178,7 @@ func TestSendMailUsingConfigAdvanced(t *testing.T) {
|
||||
headers := make(map[string]string)
|
||||
headers["TestHeader"] = "TestValue"
|
||||
|
||||
if err := SendMailUsingConfigAdvanced(mimeTo, smtpTo, from, emailSubject, emailBody, attachments, headers, cfg, true); err != nil {
|
||||
if err := SendMailUsingConfigAdvanced(mimeTo, smtpTo, from, replyTo, emailSubject, emailBody, attachments, headers, cfg, true); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should connect to the STMP Server")
|
||||
} else {
|
||||
|
||||
@@ -163,6 +163,7 @@
|
||||
"RequireEmailVerification": false,
|
||||
"FeedbackName": "",
|
||||
"FeedbackEmail": "test@example.com",
|
||||
"ReplyToAddress": "test@example.com",
|
||||
"FeedbackOrganization": "",
|
||||
"EnableSMTPAuth": false,
|
||||
"SMTPUsername": "",
|
||||
|
||||
Ссылка в новой задаче
Block a user