Skip to content

Commit

Permalink
mail: allow PLAIN auth over non-tls connections
Browse files Browse the repository at this point in the history
This allows mattermost to use a non-tls connection with a SMTP server that
supports PLAIN auth (but not LOGIN). The go library explicitly allows PLAIN
auth over non-tls connections - https://golang.org/src/net/smtp/auth.go#L55

Fixes mattermost#2929
  • Loading branch information
gramakri committed May 10, 2016
1 parent 3eebd15 commit 0475805
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions utils/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ func newSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.Ap
l4g.Error(T("utils.mail.new_client.open.error"), err)
return nil, model.NewLocAppError("SendMail", "utils.mail.connect_smtp.open_tls.app_error", nil, err.Error())
}
// GO does not support plain auth over a non encrypted connection.
// so if not tls then no auth
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 {
Expand All @@ -68,6 +66,10 @@ func newSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.Ap
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.SMTPUsername != "" { // note: go library only supports PLAIN auth over non-tls connections
if err = c.Auth(auth); err != nil {
return nil, model.NewLocAppError("SendMail", "utils.mail.new_client.auth.app_error", nil, err.Error())
}
}
return c, nil
}
Expand Down

0 comments on commit 0475805

Please sign in to comment.