Merge pull request #11 from mattermost/mm-1228
MM-1228 - Ability to use local mail config.
Этот коммит содержится в:
@@ -57,6 +57,7 @@
|
|||||||
"SMTPUsername": "",
|
"SMTPUsername": "",
|
||||||
"SMTPPassword": "",
|
"SMTPPassword": "",
|
||||||
"SMTPServer": "",
|
"SMTPServer": "",
|
||||||
|
"UseTLS": true,
|
||||||
"FeedbackEmail": "feedback@xxxxxxmustbefilledin.com",
|
"FeedbackEmail": "feedback@xxxxxxmustbefilledin.com",
|
||||||
"FeedbackName": "",
|
"FeedbackName": "",
|
||||||
"ApplePushServer": "",
|
"ApplePushServer": "",
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ type EmailSettings struct {
|
|||||||
SMTPUsername string
|
SMTPUsername string
|
||||||
SMTPPassword string
|
SMTPPassword string
|
||||||
SMTPServer string
|
SMTPServer string
|
||||||
|
UseTLS bool
|
||||||
FeedbackEmail string
|
FeedbackEmail string
|
||||||
FeedbackName string
|
FeedbackName string
|
||||||
ApplePushServer string
|
ApplePushServer string
|
||||||
|
|||||||
@@ -40,16 +40,23 @@ func SendMail(to, subject, body string) *model.AppError {
|
|||||||
|
|
||||||
auth := smtp.PlainAuth("", Cfg.EmailSettings.SMTPUsername, Cfg.EmailSettings.SMTPPassword, host)
|
auth := smtp.PlainAuth("", Cfg.EmailSettings.SMTPUsername, Cfg.EmailSettings.SMTPPassword, host)
|
||||||
|
|
||||||
tlsconfig := &tls.Config{
|
if Cfg.EmailSettings.UseTLS {
|
||||||
InsecureSkipVerify: true,
|
tlsconfig := &tls.Config{
|
||||||
ServerName: host,
|
InsecureSkipVerify: true,
|
||||||
|
ServerName: host,
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := tls.Dial("tcp", Cfg.EmailSettings.SMTPServer, tlsconfig)
|
||||||
|
if err != nil {
|
||||||
|
return model.NewAppError("SendMail", "Failed to open TLS connection", err.Error())
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := tls.Dial("tcp", Cfg.EmailSettings.SMTPServer, tlsconfig)
|
conn, err := net.Dial("tcp", Cfg.EmailSettings.SMTPServer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("SendMail", "Failed to open TLS connection", err.Error())
|
return model.NewAppError("SendMail", "Failed to open connection", err.Error())
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
c, err := smtp.NewClient(conn, host)
|
c, err := smtp.NewClient(conn, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -59,8 +66,12 @@ func SendMail(to, subject, body string) *model.AppError {
|
|||||||
defer c.Quit()
|
defer c.Quit()
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
if err = c.Auth(auth); err != nil {
|
// GO does not support plain auth over a non encrypted connection.
|
||||||
return model.NewAppError("SendMail", "Failed to authenticate on SMTP server", err.Error())
|
// so if not tls then no auth
|
||||||
|
if Cfg.EmailSettings.UseTLS {
|
||||||
|
if err = c.Auth(auth); err != nil {
|
||||||
|
return model.NewAppError("SendMail", "Failed to authenticate on SMTP server", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.Mail(fromMail.Address); err != nil {
|
if err = c.Mail(fromMail.Address); err != nil {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user