Merge pull request #4375 from ywk253100/180308_smtp_tls

Do the authentication with CRAM-MD5 when the connection is insecure
This commit is contained in:
Wenkai Yin 2018-03-08 17:42:18 +08:00 committed by GitHub
commit 685140cda8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {