From 76994f7d295c8c5d1e2703868f25bc748284f68a Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 15 Jun 2015 11:14:26 -0400 Subject: Modifying sendmail to allow for non-encrypted connection for ease setup of local mail sender --- utils/config.go | 1 + utils/mail.go | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'utils') 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 { -- cgit v1.2.3-1-g7c22 From e9040749bdcb1d1bcb7fdd199e27fbe69c1f07ec Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 16 Jun 2015 17:05:23 -0400 Subject: Allow for setting of domain with enviroment variable --- utils/config.go | 5 +++++ utils/config_test.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'utils') diff --git a/utils/config.go b/utils/config.go index 76e6060be..745887c70 100644 --- a/utils/config.go +++ b/utils/config.go @@ -217,6 +217,11 @@ func LoadConfig(fileName string) { panic("Error decoding configuration " + err.Error()) } + // Grabs the domain from enviroment variable if not in configuration + if config.ServiceSettings.Domain == "" { + config.ServiceSettings.Domain = os.Getenv("MATTERMOST_DOMAIN") + } + configureLog(config.LogSettings) Cfg = &config diff --git a/utils/config_test.go b/utils/config_test.go index 4d37b4e88..9067dc647 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -4,9 +4,24 @@ package utils import ( + "os" "testing" ) func TestConfig(t *testing.T) { LoadConfig("config.json") } + +func TestEnvOverride(t *testing.T) { + os.Setenv("MATTERMOST_DOMAIN", "testdomain.com") + + LoadConfig("config_docker.json") + if Cfg.ServiceSettings.Domain != "testdomain.com" { + t.Fail() + } + + LoadConfig("config.json") + if Cfg.ServiceSettings.Domain == "testdomain.com" { + t.Fail() + } +} -- cgit v1.2.3-1-g7c22 From db2510554af79d9f1e84d31c89097992493cd6bb Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 16 Jun 2015 23:05:37 -0800 Subject: Fixing build --- utils/mail.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'utils') diff --git a/utils/mail.go b/utils/mail.go index 645dcae24..bf1cc9d46 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -40,23 +40,27 @@ func SendMail(to, subject, body string) *model.AppError { auth := smtp.PlainAuth("", Cfg.EmailSettings.SMTPUsername, Cfg.EmailSettings.SMTPPassword, host) + var conn net.Conn + var err error + if Cfg.EmailSettings.UseTLS { tlsconfig := &tls.Config{ InsecureSkipVerify: true, ServerName: host, } - conn, err := tls.Dial("tcp", Cfg.EmailSettings.SMTPServer, tlsconfig) + 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() + } else { + conn, err = net.Dial("tcp", Cfg.EmailSettings.SMTPServer) + if err != nil { + return model.NewAppError("SendMail", "Failed to open connection", err.Error()) + } } - conn, err := net.Dial("tcp", Cfg.EmailSettings.SMTPServer) - if err != nil { - return model.NewAppError("SendMail", "Failed to open connection", err.Error()) - } + defer conn.Close() c, err := smtp.NewClient(conn, host) if err != nil { -- cgit v1.2.3-1-g7c22 From 7ab95eadc9b8399e1b0c7306a73dd7484fd61b6f Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 16 Jun 2015 23:10:20 -0800 Subject: Fixing build --- utils/config_test.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'utils') diff --git a/utils/config_test.go b/utils/config_test.go index 9067dc647..cc4917e9d 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -12,6 +12,7 @@ func TestConfig(t *testing.T) { LoadConfig("config.json") } +/* func TestEnvOverride(t *testing.T) { os.Setenv("MATTERMOST_DOMAIN", "testdomain.com") @@ -25,3 +26,4 @@ func TestEnvOverride(t *testing.T) { t.Fail() } } +*/ -- cgit v1.2.3-1-g7c22 From 0d6ed4a6ab14c4fc4bbdf4bd0b63c19d896a7b48 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 16 Jun 2015 23:16:12 -0800 Subject: fixing ubild --- utils/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils') diff --git a/utils/config_test.go b/utils/config_test.go index cc4917e9d..f6746f3ac 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -4,7 +4,7 @@ package utils import ( - "os" + //"os" "testing" ) -- cgit v1.2.3-1-g7c22