don't give smtp plainauth if no username & password

for #141, just a guess
This commit is contained in:
Harvey Tindall 2021-08-26 21:03:02 +01:00
parent e67b2e91fb
commit 548dceda28
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
2 changed files with 11 additions and 5 deletions

View File

@ -246,7 +246,7 @@
"requires_restart": true,
"type": "text",
"value": "",
"description": "URL base for when running jfa-go with a reverse proxy in a subfolder."
"description": "URL base for when running jfa-go with a reverse proxy in a subfolder. include preceding /, e.g \"/accounts\"."
}
}
},

View File

@ -181,8 +181,7 @@ func (emailer *Emailer) NewMailgun(url, key string) {
func (emailer *Emailer) NewSMTP(server string, port int, username, password string, sslTLS bool, certPath string) (err error) {
// x509.SystemCertPool is unavailable on windows
if PLATFORM == "windows" {
emailer.sender = &SMTP{
auth: smtp.PlainAuth("", username, password, server),
sender := &SMTP{
server: server,
port: port,
sslTLS: sslTLS,
@ -191,6 +190,10 @@ func (emailer *Emailer) NewSMTP(server string, port int, username, password stri
ServerName: server,
},
}
if username != "" || password != "" {
sender.auth = smtp.PlainAuth("", username, password, server)
}
emailer.sender = sender
return
}
rootCAs, err := x509.SystemCertPool()
@ -204,8 +207,7 @@ func (emailer *Emailer) NewSMTP(server string, port int, username, password stri
err = errors.New("Failed to append cert to pool")
}
}
emailer.sender = &SMTP{
auth: smtp.PlainAuth("", username, password, server),
sender := &SMTP{
server: server,
port: port,
sslTLS: sslTLS,
@ -215,6 +217,10 @@ func (emailer *Emailer) NewSMTP(server string, port int, username, password stri
RootCAs: rootCAs,
},
}
if username != "" || password != "" {
sender.auth = smtp.PlainAuth("", username, password, server)
}
emailer.sender = sender
return
}