diff options
author | AJ Moon <moonmeister@users.noreply.github.com> | 2017-07-31 08:15:01 -0700 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-07-31 08:15:01 -0700 |
commit | 6f4e38d129ffaf469d40fc8596d3957ee94d21e9 (patch) | |
tree | 72e90090bc46dee66b84a12d026fc3764c702a2d /utils | |
parent | cf32b59e645bbba562485606be7fbc5cd2fede30 (diff) | |
download | chat-6f4e38d129ffaf469d40fc8596d3957ee94d21e9.tar.gz chat-6f4e38d129ffaf469d40fc8596d3957ee94d21e9.tar.bz2 chat-6f4e38d129ffaf469d40fc8596d3957ee94d21e9.zip |
[GH-6366] Add functionality to disable Authentication when connecting to SMTP (#6639)
* Issue #6366: Add feature to disable auth for Encrypted connections to SMTP settings.
* Clean PLAIN AUTH Option
* Reorder SMTP server setup and change helptext
* remove unneeded setting and modify logic
* text description change
Diffstat (limited to 'utils')
-rw-r--r-- | utils/mail.go | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/utils/mail.go b/utils/mail.go index 4b3102424..41011d67e 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -6,13 +6,14 @@ package utils import ( "crypto/tls" "fmt" - l4g "github.com/alecthomas/log4go" - "github.com/mattermost/platform/model" "mime" "net" "net/mail" "net/smtp" "time" + + l4g "github.com/alecthomas/log4go" + "github.com/mattermost/platform/model" ) func encodeRFC2047Word(s string) string { @@ -59,22 +60,17 @@ func newSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.Ap } } - auth := smtp.PlainAuth("", config.EmailSettings.SMTPUsername, config.EmailSettings.SMTPPassword, config.EmailSettings.SMTPServer+":"+config.EmailSettings.SMTPPort) - if config.EmailSettings.ConnectionSecurity == model.CONN_SECURITY_TLS { - if err = c.Auth(auth); err != nil { - return nil, model.NewLocAppError("SendMail", "utils.mail.new_client.auth.app_error", nil, err.Error()) - } - } else if config.EmailSettings.ConnectionSecurity == model.CONN_SECURITY_STARTTLS { + if config.EmailSettings.ConnectionSecurity == model.CONN_SECURITY_STARTTLS { tlsconfig := &tls.Config{ InsecureSkipVerify: *config.EmailSettings.SkipServerCertificateVerification, ServerName: config.EmailSettings.SMTPServer, } c.StartTLS(tlsconfig) - if err = c.Auth(auth); err != nil { - return nil, model.NewLocAppError("SendMail", "utils.mail.new_client.auth.app_error", nil, err.Error()) - } - } else if config.EmailSettings.ConnectionSecurity == model.CONN_SECURITY_PLAIN { - // note: go library only supports PLAIN auth over non-tls connections + } + + if *config.EmailSettings.EnableSMTPAuth { + auth := smtp.PlainAuth("", config.EmailSettings.SMTPUsername, config.EmailSettings.SMTPPassword, config.EmailSettings.SMTPServer+":"+config.EmailSettings.SMTPPort) + if err = c.Auth(auth); err != nil { return nil, model.NewLocAppError("SendMail", "utils.mail.new_client.auth.app_error", nil, err.Error()) } |