summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-12 15:23:33 -0700
committerGitHub <noreply@github.com>2017-10-12 15:23:33 -0700
commit8966452d1183e94fecc373b9d08c65a0573cbbc6 (patch)
treefd46088948e85133237fe49ac2e0cbf270154e74 /utils
parentaa2b82727f0f1b3edb79f6d31c04b8fd0d718455 (diff)
downloadchat-8966452d1183e94fecc373b9d08c65a0573cbbc6.tar.gz
chat-8966452d1183e94fecc373b9d08c65a0573cbbc6.tar.bz2
chat-8966452d1183e94fecc373b9d08c65a0573cbbc6.zip
workaround for go smtp bug (#7620)
Diffstat (limited to 'utils')
-rw-r--r--utils/mail.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/utils/mail.go b/utils/mail.go
index 7be1303d1..9bda4ee39 100644
--- a/utils/mail.go
+++ b/utils/mail.go
@@ -7,14 +7,13 @@ import (
"crypto/tls"
"mime"
"net"
+ "net/http"
"net/mail"
"net/smtp"
"time"
"gopkg.in/gomail.v2"
- "net/http"
-
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/html2text"
"github.com/mattermost/mattermost-server/model"
@@ -48,6 +47,20 @@ func connectToSMTPServer(config *model.Config) (net.Conn, *model.AppError) {
return conn, nil
}
+// TODO: Remove once this bug is fixed: https://github.com/golang/go/issues/22166
+type plainAuthOverTLSConn struct {
+ smtp.Auth
+}
+
+func PlainAuthOverTLSConn(identity, username, password, host string) smtp.Auth {
+ return &plainAuthOverTLSConn{smtp.PlainAuth(identity, username, password, host)}
+}
+
+func (a *plainAuthOverTLSConn) Start(server *smtp.ServerInfo) (string, []byte, error) {
+ server.TLS = true
+ return a.Auth.Start(server)
+}
+
func newSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.AppError) {
c, err := smtp.NewClient(conn, config.EmailSettings.SMTPServer+":"+config.EmailSettings.SMTPPort)
if err != nil {
@@ -73,7 +86,12 @@ func newSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.Ap
}
if *config.EmailSettings.EnableSMTPAuth {
- auth := smtp.PlainAuth("", config.EmailSettings.SMTPUsername, config.EmailSettings.SMTPPassword, config.EmailSettings.SMTPServer+":"+config.EmailSettings.SMTPPort)
+ var auth smtp.Auth
+ if _, ok := conn.(*tls.Conn); ok {
+ auth = PlainAuthOverTLSConn("", config.EmailSettings.SMTPUsername, config.EmailSettings.SMTPPassword, config.EmailSettings.SMTPServer+":"+config.EmailSettings.SMTPPort)
+ } else {
+ 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.NewAppError("SendMail", "utils.mail.new_client.auth.app_error", nil, err.Error(), http.StatusInternalServerError)