SMTP 异常。要求认证?
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage()
{
Subject = "Subject",
Body = "Body"
};
message.To.Add(new MailAddress("[email protected]", "Some name"));
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Send(message);
}
配置
<configuration>
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="****" defaultCredentials="false" port="587" userName="****" password="****" />
</smtp>
</mailSettings>
</system.net>
<system.web>
修正。现在可以了。谢谢马雷克
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage()
{
Subject = "Subject",
Body = "Body"
};
message.To.Add(new MailAddress("[email protected]", "Some name"));
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Send(message);
}
config
<configuration>
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="****" defaultCredentials="false" port="587" userName="****" password="****" />
</smtp>
</mailSettings>
</system.net>
<system.web>
Correction. it works now. Thanks Marek
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题可能是
defaultCredentials
设置为 true。尝试将其设置为 false,然后重试。另外,为什么要在代码中再次设置凭据? Gmail 还要求通过 SSL(如果我没记错的话)在端口 587 上发送电子邮件。就在今天,我在代码中实现了 gmail smtp。我的设置和代码:
Your problem might be with
defaultCredentials
set to true. Try setting that to false and try again. Also, why are you setting your credentials again in code? Gmail also requires emails to be sent via SSL (if I remember correctly) on port 587.Just today I implemented gmail smtp in my code. My settings and code: