[英]ASP.NET cannot sent email from smtp
回到我以前的问题 。 我仍然无法通过Gmail SMTP发送电子邮件。 以前我有以下错误:
邮件发送失败。
但是现在我更改了一些代码,现在遇到了他的错误:
连接尝试失败,因为一段时间后连接方未正确响应,或者建立的连接失败,因为连接的主机未能响应64.233.167.109:465
我非常生气,以至于我开始使用wireshark来了解问题出在哪里。
这是我发现的:
smtp.gmail.com服务器:53.90.35.60地址:53.90.35.60#53
非权威性答案:smtp.gmail.com规范名称= gmail-smtp-msa.l.google.com。 名称:gmail-smtp-msa.L.google.com地址:64.233.167.108名称:gmail-smtp-msa.L.google.com地址:64.233.167.109
所以据我了解,有邮件smtp服务器收到响应
另外,我们在Intranet中使用代理,但是我在Web.config中的应用程序中添加了代理:
<system.net>
<defaultProxy enabled="true">
<proxy proxyaddress="proxy_was_here" bypassonlocal="true"
/>
</defaultProxy>
这是新代码的一部分:
var fromAddress = new MailAddress("email", "From Name");
var toAddress = new MailAddress("email", "To Name");
const string fromPassword = "pass";
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 465,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
如果您有任何疑问,请查看我之前的问题,或在下面的评论中写下。
请尝试使用端口号587和EnableSSL = false
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
还请在https://www.smtper.net/中使用您的凭据进行检查
并允许通过此链接提供不太安全的应用程序: https : //myaccount.google.com/lesssecureapps?pli=1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.