fix(email): skip SMTP AUTH when Login and Password are empty (fixes #7267) (#7269)
What changed, and why it matters
This commit fixes an email-sending bug in BTCPay Server. When an administrator configured an SMTP relay that does not require a username or password, BTCPay was still trying to log in if the server said it supported authentication. That caused unnecessary 535 authentication errors and prevented emails from being sent. The fix simply skips login when both the Login and Password fields are empty. There is no security vulnerability here; it is a reliability/configuration fix.
No security action required. Treat as a normal reliability fix. Reviewers may verify that empty Login/Password is an intentional supported configuration and that whitespace-only values are correctly rejected.
Security signals we found
No injection, privilege escalation, or authentication bypass introduced
Change narrows when authentication is attempted, reducing unnecessary credential submission
No secrets, tokens, or cryptographic material changed
No new dependencies or network exposure
Evidence from the diff
The change is in BTCPayServer/Plugins/Emails/Services/EmailSettings.cs. Previously, after connecting to the SMTP server, the code checked only whether the server advertised SmtpCapabilities.Authentication before calling AuthenticateAsync(Login ?? string.Empty, Password ?? string.Empty). With empty credentials against a relay that advertises AUTH but does not require it, this produced 535 authentication failures. The patch adds two extra conditions: authentication is now performed only when Login and Password are both non-whitespace. This is a functional bug fix, not a security boundary change.
Changed components
BTCPayServer/Plugins/Emails/Services/EmailSettings.csBTCPay Server email/SMTP sending pluginInspect captured patch +4 / −2
diff --git a/BTCPayServer/Plugins/Emails/Services/EmailSettings.cs b/BTCPayServer/Plugins/Emails/Services/EmailSettings.cs
index d279d6d..cfcfbae 100644
--- a/BTCPayServer/Plugins/Emails/Services/EmailSettings.cs
+++ b/BTCPayServer/Plugins/Emails/Services/EmailSettings.cs
@@ -111,8 +111,10 @@ public class EmailSettings
#pragma warning restore CA5359 // Do Not Disable Certificate Validation
}
await client.ConnectAsync(Server, Port.Value, MailKit.Security.SecureSocketOptions.Auto, connectCancel.Token);
- if ((client.Capabilities & SmtpCapabilities.Authentication) != 0)
- await client.AuthenticateAsync(Login ?? string.Empty, Password ?? string.Empty, connectCancel.Token);
+ if ((client.Capabilities & SmtpCapabilities.Authentication) != 0
+ && !string.IsNullOrWhiteSpace(Login)
+ && !string.IsNullOrWhiteSpace(Password))
+ await client.AuthenticateAsync(Login, Password, connectCancel.Token);
}
catch
{
Why this scored 22/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.