summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/config.go6
-rw-r--r--utils/config_test.go17
-rw-r--r--utils/mail.go33
3 files changed, 47 insertions, 9 deletions
diff --git a/utils/config.go b/utils/config.go
index 1060c7550..745887c70 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
@@ -216,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..f6746f3ac 100644
--- a/utils/config_test.go
+++ b/utils/config_test.go
@@ -4,9 +4,26 @@
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()
+ }
+}
+*/
diff --git a/utils/mail.go b/utils/mail.go
index b8c2f4f9b..bf1cc9d46 100644
--- a/utils/mail.go
+++ b/utils/mail.go
@@ -40,15 +40,26 @@ 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,
+ 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)
+ if err != nil {
+ return model.NewAppError("SendMail", "Failed to open TLS connection", err.Error())
+ }
+ } else {
+ conn, err = net.Dial("tcp", Cfg.EmailSettings.SMTPServer)
+ if err != nil {
+ return model.NewAppError("SendMail", "Failed to open connection", err.Error())
+ }
}
- 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()
c, err := smtp.NewClient(conn, host)
@@ -59,8 +70,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 {