Merge pull request #11 from mattermost/mm-1228

MM-1228 - Ability to use local mail config.
This commit is contained in:
Corey Hulen
2015-06-16 09:58:53 -08:00
3 changed files with 21 additions and 8 deletions

View File

@@ -57,6 +57,7 @@
"SMTPUsername": "",
"SMTPPassword": "",
"SMTPServer": "",
"UseTLS": true,
"FeedbackEmail": "feedback@xxxxxxmustbefilledin.com",
"FeedbackName": "",
"ApplePushServer": "",

View File

@@ -79,6 +79,7 @@ type EmailSettings struct {
SMTPUsername string
SMTPPassword string
SMTPServer string
UseTLS bool
FeedbackEmail string
FeedbackName string
ApplePushServer string

View File

@@ -40,16 +40,23 @@ func SendMail(to, subject, body string) *model.AppError {
auth := smtp.PlainAuth("", Cfg.EmailSettings.SMTPUsername, Cfg.EmailSettings.SMTPPassword, host)
tlsconfig := &tls.Config{
InsecureSkipVerify: true,
ServerName: host,
if Cfg.EmailSettings.UseTLS {
tlsconfig := &tls.Config{
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 {
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)
if err != nil {
@@ -59,8 +66,12 @@ func SendMail(to, subject, body string) *model.AppError {
defer c.Quit()
defer c.Close()
if err = c.Auth(auth); err != nil {
return model.NewAppError("SendMail", "Failed to authenticate on SMTP server", err.Error())
// GO does not support plain auth over a non encrypted connection.
// 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 {