【发布时间】:2019-11-04 06:14:16
【问题描述】:
我正在尝试连接到需要身份验证的 smtp 服务器。
这是我用来发送电子邮件的 C# 代码:
var smtpClient = new SmtpClient();
smtpClient.Host = _smtpServerHost;
smtpClient.Credentials = new NetworkCredential(_username, _password);
smtpClient.UseDefaultCredentials = false;
smtpClient.Send(GetMessage());
发送函数引发错误:
The SMTP server requires a secure connection or the client was not authenticated.
The server response was: Must authenticate before sending mail
我是否缺少连接到 smtp 服务器的步骤?
我尝试连接到我们正在运行的测试服务器,但没有成功。我还尝试连接到smtp4dev。当我不需要身份验证时,我可以连接到它,但在我需要身份验证时不能。
【问题讨论】:
-
您确定您使用的凭据正确吗?
-
我正在使用身份验证,但我没有使用
smtpClient.UseDefaultCredentials = false;行 - 你试过删除它吗? -
你可以尝试直接telnet到25端口连接服务器,并尝试验证computerperformance.co.uk/exchange2003/…。或者,查看引发的异常,特别是内部异常