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(""),
|
SMTPPassword: model.NewString(""),
|
||||||
FeedbackName: model.NewString(""),
|
FeedbackName: model.NewString(""),
|
||||||
FeedbackEmail: model.NewString(""),
|
FeedbackEmail: model.NewString(""),
|
||||||
|
ReplyToAddress: model.NewString(""),
|
||||||
SendEmailNotifications: model.NewBool(false),
|
SendEmailNotifications: model.NewBool(false),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -389,6 +389,7 @@ func (a *App) trackConfig() {
|
|||||||
"enable_preview_mode_banner": *cfg.EmailSettings.EnablePreviewModeBanner,
|
"enable_preview_mode_banner": *cfg.EmailSettings.EnablePreviewModeBanner,
|
||||||
"isdefault_feedback_name": isDefault(cfg.EmailSettings.FeedbackName, ""),
|
"isdefault_feedback_name": isDefault(cfg.EmailSettings.FeedbackName, ""),
|
||||||
"isdefault_feedback_email": isDefault(cfg.EmailSettings.FeedbackEmail, ""),
|
"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),
|
"isdefault_feedback_organization": isDefault(*cfg.EmailSettings.FeedbackOrganization, model.EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION),
|
||||||
"skip_server_certificate_verification": *cfg.EmailSettings.SkipServerCertificateVerification,
|
"skip_server_certificate_verification": *cfg.EmailSettings.SkipServerCertificateVerification,
|
||||||
"isdefault_login_button_color": isDefault(*cfg.EmailSettings.LoginButtonColor, ""),
|
"isdefault_login_button_color": isDefault(*cfg.EmailSettings.LoginButtonColor, ""),
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ package:
|
|||||||
@# Reset email sending to original configuration
|
@# Reset email sending to original configuration
|
||||||
sed -i'' -e 's|"SendEmailNotifications": true,|"SendEmailNotifications": false,|g' $(DIST_PATH)/config/config.json
|
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|"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|"SMTPServer": "dockerhost",|"SMTPServer": "",|g' $(DIST_PATH)/config/config.json
|
||||||
sed -i'' -e 's|"SMTPPort": "2500",|"SMTPPort": "",|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,
|
"RequireEmailVerification": false,
|
||||||
"FeedbackName": "",
|
"FeedbackName": "",
|
||||||
"FeedbackEmail": "test@example.com",
|
"FeedbackEmail": "test@example.com",
|
||||||
|
"ReplyToAddress": "test@example.com",
|
||||||
"FeedbackOrganization": "",
|
"FeedbackOrganization": "",
|
||||||
"EnableSMTPAuth": false,
|
"EnableSMTPAuth": false,
|
||||||
"SMTPUsername": "",
|
"SMTPUsername": "",
|
||||||
|
|||||||
@@ -1020,6 +1020,7 @@ type EmailSettings struct {
|
|||||||
RequireEmailVerification *bool
|
RequireEmailVerification *bool
|
||||||
FeedbackName *string
|
FeedbackName *string
|
||||||
FeedbackEmail *string
|
FeedbackEmail *string
|
||||||
|
ReplyToAddress *string
|
||||||
FeedbackOrganization *string
|
FeedbackOrganization *string
|
||||||
EnableSMTPAuth *bool
|
EnableSMTPAuth *bool
|
||||||
SMTPUsername *string
|
SMTPUsername *string
|
||||||
@@ -1075,6 +1076,10 @@ func (s *EmailSettings) SetDefaults() {
|
|||||||
s.FeedbackEmail = NewString("test@example.com")
|
s.FeedbackEmail = NewString("test@example.com")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.ReplyToAddress == nil {
|
||||||
|
s.ReplyToAddress = NewString("test@example.com")
|
||||||
|
}
|
||||||
|
|
||||||
if s.FeedbackOrganization == nil {
|
if s.FeedbackOrganization == nil {
|
||||||
s.FeedbackOrganization = NewString(EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION)
|
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 {
|
func SendMailUsingConfig(to, subject, htmlBody string, config *model.Config, enableComplianceFeatures bool) *model.AppError {
|
||||||
fromMail := mail.Address{Name: *config.EmailSettings.FeedbackName, Address: *config.EmailSettings.FeedbackEmail}
|
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
|
// 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 {
|
if !*config.EmailSettings.SendEmailNotifications || len(*config.EmailSettings.SMTPServer) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -227,10 +228,10 @@ func SendMailUsingConfigAdvanced(mimeTo, smtpTo string, from mail.Address, subje
|
|||||||
return err
|
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))
|
mlog.Debug(fmt.Sprintf("sending mail to %v with subject of '%v'", smtpTo, subject))
|
||||||
|
|
||||||
htmlMessage := "\r\n<html><body>" + htmlBody + "</body></html>"
|
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{
|
headers := map[string][]string{
|
||||||
"From": {from.String()},
|
"From": {from.String()},
|
||||||
|
"Reply-To": {replyTo.String()},
|
||||||
"To": {mimeTo},
|
"To": {mimeTo},
|
||||||
"Subject": {encodeRFC2047Word(subject)},
|
"Subject": {encodeRFC2047Word(subject)},
|
||||||
"Content-Transfer-Encoding": {"8bit"},
|
"Content-Transfer-Encoding": {"8bit"},
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ func TestSendMailUsingConfigAdvanced(t *testing.T) {
|
|||||||
var mimeTo = "test@example.com"
|
var mimeTo = "test@example.com"
|
||||||
var smtpTo = "test2@example.com"
|
var smtpTo = "test2@example.com"
|
||||||
var from = mail.Address{Name: "Nobody", Address: "nobody@mattermost.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 emailSubject = "Testing this email"
|
||||||
var emailBody = "This is a test from autobot"
|
var emailBody = "This is a test from autobot"
|
||||||
|
|
||||||
@@ -177,7 +178,7 @@ func TestSendMailUsingConfigAdvanced(t *testing.T) {
|
|||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
headers["TestHeader"] = "TestValue"
|
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.Log(err)
|
||||||
t.Fatal("Should connect to the STMP Server")
|
t.Fatal("Should connect to the STMP Server")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -163,6 +163,7 @@
|
|||||||
"RequireEmailVerification": false,
|
"RequireEmailVerification": false,
|
||||||
"FeedbackName": "",
|
"FeedbackName": "",
|
||||||
"FeedbackEmail": "test@example.com",
|
"FeedbackEmail": "test@example.com",
|
||||||
|
"ReplyToAddress": "test@example.com",
|
||||||
"FeedbackOrganization": "",
|
"FeedbackOrganization": "",
|
||||||
"EnableSMTPAuth": false,
|
"EnableSMTPAuth": false,
|
||||||
"SMTPUsername": "",
|
"SMTPUsername": "",
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user