问题描述
我正在尝试从 C# 应用程序发送带有我网站地址的电子邮件.
直到最近,这几个月都运行良好.(也许我的提供者改变了一些东西或者其他人改变了设置)
I'm trying to send email with my website's address from a C# application.
This worked fine for several months until recently. (maybe my provider changes some things or someone else changed settings)
代码如下:
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);
}
这是错误:
SMTP 服务器需要安全连接或客户端未通过身份验证.服务器响应为:需要 SMTP 身份验证.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required.
查看其他问题,我尝试了他们的建议,使 SmtpServer.EnableSsl = true
.这根本不起作用.它给出了以下内容:
Looking at other questions I tried what they suggested, to make SmtpServer.EnableSsl = true
. This didn't work at all. It gave the following:
System.Net.Mail.SmtpException:服务器不支持安全连接.
System.Net.Mail.SmtpException: Server does not support secure connections.
我猜我应该禁用 SSL 并按照以前的方式使用它.
I'm guessing I should disable SSL and have it the way it was before.
有什么建议可以让电子邮件再次发送工作吗?
Any suggestions how to make email sending work again?
编辑
我试过没有 SmtpServer.UseDefaultCredentials = false;
我尝试将其设置为 true:SmtpServer.UseDefaultCredentials =true;
我尝试将该行与以下 //SmtpServer.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);
推荐答案
该错误消息通常由以下原因之一引起:
That error message is typically caused by one of the following:
- 连接设置不正确,例如为安全或非安全连接指定了错误的端口
- 凭据不正确.我会验证用户名和密码组合,以确保凭据正确.
这篇关于System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!