我正在尝试从 C# 应用程序发送包含我网站地址的电子邮件。
直到最近,这几个月都运行良好。 (也许我的供应商改变了一些东西或其他人改变了设置)
代码如下:
private void sendEmail(Email invite) {
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(smtpServerName);
mail.From = new MailAddress(emailUsername);
mail.To.Add(invite.RecipientEmail);
mail.Subject = invite.MessageSubject;
mail.Body = invite.MessageBody;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);
// SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
这是错误:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required.
查看其他问题,我尝试了他们的建议,使 SmtpServer.EnableSsl = true
。这根本不起作用。它给出了以下内容:
System.Net.Mail.SmtpException: Server does not support secure connections.
我猜我应该禁用 SSL 并像以前一样使用它。
有什么建议可以重新发送电子邮件吗?
编辑
我试过没有 SmtpServer.UseDefaultCredentials = false;
我尝试将其设置为 true:SmtpServer.UseDefaultCredentials =true;
我尝试对该行以及以下 //SmtpServer.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);
最佳答案
该错误消息通常是由以下原因之一引起的:
- 不正确的连接设置,例如为安全或非安全连接指定的错误端口
- 凭据不正确。我会验证用户名和密码组合,以确保凭据正确无误。
关于c# - 系统.Net.Mail.SmtpException : The SMTP server requires a secure connection or the client was not authenticated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13773810/