通过 Google SMTP 发送邮件失败
我仍然收到“发送邮件失败”的消息。例外。内部异常是“无法连接到远程服务器”,内部异常是“连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机未能响应” ”。我很确定这不是防火墙设置的原因。有谁知道我能做什么?谢谢。
var mail = new MailMessage("[email protected]", "[email protected]")
{
Subject = "Testing subject",
Body = "Testing body"
};
try
{
var client = new SmtpClient("smtp.google.com", 465)
{
EnableSsl = true,
Credentials = new NetworkCredential("[email protected]", "password")
};
client.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
I'm still getting "Failure sending mail." exception. The inner exception is "Unable to connect to the remote server" and the inner exception of that is "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". I'm pretty sure the cause of this is not the firewall setting. Does anyone know what I can do about it? Thanks.
var mail = new MailMessage("[email protected]", "[email protected]")
{
Subject = "Testing subject",
Body = "Testing body"
};
try
{
var client = new SmtpClient("smtp.google.com", 465)
{
EnableSsl = true,
Credentials = new NetworkCredential("[email protected]", "password")
};
client.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
以下是所需的 Google 设置:
传入邮件 (POP3) 服务器 - 需要 SSL:pop.gmail.com
使用 SSL:是
端口:995
发送邮件 (SMTP) 服务器 - 需要 TLS3 或 SSL:smtp.gmail.com
(使用身份验证)
使用身份验证:是
TLS/STARTTLS 端口:587
SSL 端口:465
帐户名称:您的完整电子邮件地址(包括@gmail.com 或
@your_domain.com)
电子邮件地址:您的电子邮件地址([电子邮件受保护] 或
用户名@your_domain.com)
密码:您的 Gmail 密码
Here is the Google settings needed:
Incoming Mail (POP3) Server - requires SSL: pop.gmail.com
Use SSL: Yes
Port: 995
Outgoing Mail (SMTP) Server - requires TLS3 or SSL: smtp.gmail.com
(use authentication)
Use Authentication: Yes
Port for TLS/STARTTLS: 587
Port for SSL: 465
Account Name: your full email address (including @gmail.com or
@your_domain.com)
Email Address: your email address ([email protected] or
username@your_domain.com)
Password: your Gmail password
我认为 465 不是正确的端口。你试过587吗? SMTP 服务器是
smtp.gmail.com
。I don't think 465 is the right port. Have you tried 587? And the SMTP server is
smtp.gmail.com
.我也在使用Godaddy电子邮件服务器,下面的代码对我来说效果很好:
命名空间:
============
I am also working with Godaddy email server and below code worked fine for me:
Namespace:
============
如果主机名正确并且谷歌支持基于 SSL 的 SMTP,那么它会被某些东西阻止,我将开始检查防火墙。
If the hostname is correct and google supports SMTP over SSL, then it is being blocked by something and I would start checking firewalls.
我不认为 smtp.google.com 是正确的 Gmail 服务器。您是否在端口 25 上尝试过 smtp.gmail.com?
端口 465 用于通过 SSL 的 SMTP,.NET SmtpClient 不支持该端口。相反,请使用端口 25。SMTP 客户端将使用 STARTTLS 功能来加密通信。
I don't think smtp.google.com is right server for gmail. Have you tried smtp.gmail.com on port 25?
Port 465 is for SMTP via SSL, which is not supported by the .NET SmtpClient. Instead, use port 25. The SMTP Client will use the STARTTLS feature to encrypt the communication.
smtpclient 类的正确端口是 587
the correct port is 587 for smtpclient class