summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-06-15 11:14:26 -0400
committerChristopher Speller <crspeller@gmail.com>2015-06-15 11:19:48 -0400
commit76994f7d295c8c5d1e2703868f25bc748284f68a (patch)
tree5b05075e2684b0e7b084e67bab2af03f32e42d85
parentc94883e0dfc0c7cbcf86a78f9134d1e3283a07cd (diff)
downloadchat-76994f7d295c8c5d1e2703868f25bc748284f68a.tar.gz
chat-76994f7d295c8c5d1e2703868f25bc748284f68a.tar.bz2
chat-76994f7d295c8c5d1e2703868f25bc748284f68a.zip
Modifying sendmail to allow for non-encrypted connection for ease setup of local mail sender
-rw-r--r--config/config.json1
-rw-r--r--utils/config.go1
-rw-r--r--utils/mail.go27
3 files changed, 21 insertions, 8 deletions
diff --git a/config/config.json b/config/config.json
index 4eab907f7..955947a83 100644
--- a/config/config.json
+++ b/config/config.json
@@ -57,6 +57,7 @@
"SMTPUsername": "",
"SMTPPassword": "",
"SMTPServer": "",
+ "UseTLS": true,
"FeedbackEmail": "feedback@xxxxxxmustbefilledin.com",
"FeedbackName": "",
"ApplePushServer": "",
diff --git a/utils/config.go b/utils/config.go
index b6688de68..37da59315 100644
--- a/utils/config.go
+++ b/utils/config.go
@@ -79,6 +79,7 @@ type EmailSettings struct {
SMTPUsername string
SMTPPassword string
SMTPServer string
+ UseTLS bool
FeedbackEmail string
FeedbackName string
ApplePushServer string
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 {