diff options
author | Corey Hulen <corey@hulen.com> | 2015-06-16 09:58:53 -0800 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2015-06-16 09:58:53 -0800 |
commit | a3ff4116d95f5b79809e1ac15d4418d9b668779b (patch) | |
tree | f90aaf714fbc2ec3839b826894a4f436c50ccc06 /utils/mail.go | |
parent | 48a16cea6409b7358562d7131151a51f6b80a765 (diff) | |
parent | 76994f7d295c8c5d1e2703868f25bc748284f68a (diff) | |
download | chat-a3ff4116d95f5b79809e1ac15d4418d9b668779b.tar.gz chat-a3ff4116d95f5b79809e1ac15d4418d9b668779b.tar.bz2 chat-a3ff4116d95f5b79809e1ac15d4418d9b668779b.zip |
Merge pull request #11 from mattermost/mm-1228
MM-1228 - Ability to use local mail config.
Diffstat (limited to 'utils/mail.go')
-rw-r--r-- | utils/mail.go | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/utils/mail.go b/utils/mail.go index b8c2f4f9b..645dcae24 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -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 { |