From 0a8929b85e2345697e354bd0426ddd6552211e41 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 8 Mar 2018 14:21:44 +0800 Subject: [PATCH] Do the authentication with CRAM-MD5 when the connection is insecure --- src/common/utils/email/mail.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/utils/email/mail.go b/src/common/utils/email/mail.go index e2623e18e..f91830b69 100644 --- a/src/common/utils/email/mail.go +++ b/src/common/utils/email/mail.go @@ -130,6 +130,7 @@ func newClient(addr, identity, username, password string, }); err != nil { return nil, err } + tls = true } else { log.Debugf("the email server %s does not support STARTTLS", addr) } @@ -137,9 +138,13 @@ func newClient(addr, identity, username, password string, if ok, _ := client.Extension("AUTH"); ok { log.Debug("authenticating the client...") - // only support plain auth - if err = client.Auth(smtp.PlainAuth(identity, - username, password, host)); err != nil { + var auth smtp.Auth + if tls { + auth = smtp.PlainAuth(identity, username, password, host) + } else { + auth = smtp.CRAMMD5Auth(username, password) + } + if err = client.Auth(auth); err != nil { return nil, err } } else {