[英]ASP.NET cannot sent email from smtp
back to my previous question . 回到我以前的问题 。 I am still have problem with sending email by Gmail SMTP.
我仍然无法通过Gmail SMTP发送电子邮件。 Previously i had error that:
以前我有以下错误:
Failure sending mail.
邮件发送失败。
But now i changed some code and now i have his error: 但是现在我更改了一些代码,现在遇到了他的错误:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 64.233.167.109:465
连接尝试失败,因为一段时间后连接方未正确响应,或者建立的连接失败,因为连接的主机未能响应64.233.167.109:465
I was so pissed off, that I started using wireshark to understand where the problem. 我非常生气,以至于我开始使用wireshark来了解问题出在哪里。
Here is what i found: 这是我发现的:
smtp.gmail.com Server: 53.90.35.60 Address: 53.90.35.60#53
smtp.gmail.com服务器:53.90.35.60地址:53.90.35.60#53
Non-authoritative answer: smtp.gmail.com canonical name = gmail-smtp-msa.l.google.com.
非权威性答案:smtp.gmail.com规范名称= gmail-smtp-msa.l.google.com。 Name: gmail-smtp-msa.L.google.com Address: 64.233.167.108 Name: gmail-smtp-msa.L.google.com Address: 64.233.167.109
名称:gmail-smtp-msa.L.google.com地址:64.233.167.108名称:gmail-smtp-msa.L.google.com地址:64.233.167.109
so as I understand there is response received from mail smtp server 所以据我了解,有邮件smtp服务器收到响应
Also we use proxy in our intranet, but I added proxy in my application, inside Web.config: 另外,我们在Intranet中使用代理,但是我在Web.config中的应用程序中添加了代理:
<system.net>
<defaultProxy enabled="true">
<proxy proxyaddress="proxy_was_here" bypassonlocal="true"
/>
</defaultProxy>
and here is the part of new code: 这是新代码的一部分:
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);
}
If you have any questions, please look at my previous question or just write in the comments below. 如果您有任何疑问,请查看我之前的问题,或在下面的评论中写下。
Please try with port number 587 and EnableSSL = false 请尝试使用端口号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)
};
also check with your credentials in https://www.smtper.net/ 还请在https://www.smtper.net/中使用您的凭据进行检查
and also allow for less secure app from this link : https://myaccount.google.com/lesssecureapps?pli=1 并允许通过此链接提供不太安全的应用程序: https : //myaccount.google.com/lesssecureapps?pli=1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.