且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#WinForms应用程序失败在发送电子邮件:远程名称无法解析:'smtp.gmail.com;操作超时

更新时间:2022-10-14 18:57:30

尝试一些基本的网络故障排除。首先,确保你可以通过IP地址ping通的东西,这并不需要DNS来工作,所以尽量平173.194.41.86 ,看看你得到一些回复。

然后平www.gmail.com从你的机器平www.gmail.com 。这应该告诉你,如果你的网络可以解决任何名称为IP地址。你应该得到四个IP地址坪在响应上述相同。

如果没有,那么你的DNS配置是坏的。如果你有一个静态IP地址,那么你将需要检查与网络管理员或设置DNS服务器一样的工作机器。如果它的动态,那么你可以尝试 ipconfig / renew命令从DHCP服务器获取最新的设置。

如果侦测www.gmail.com奋力然后尝试平smtp.gmail.com 来看看如果SMTP主机解决。如果没有,那么还是有一个DNS问题,而且是一个影响只有SMTP主机名。

尝试 IPCONFIG / FLUSHDNS 清除本地DNS缓存,然后再试一次。请尝试重新启动,如果没有一个督促的服务器上。

您也可以使用 NSLOOKUP 来检查DNS域名解析,也解析-DNSNAME 在PowerShell中,可能只有在3.0虽然。

此外,检查任何防火墙设置。

My WinForms C# program sends email. I've used MailMessage and SmtpClient. In the constructor of SmtpClient I passed smtp.gmail.com and port 587.

This is working on my friend's computer, however when I try it I get this error:

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.gmail.com'

System.Net.Mail.SmtpException: Operation Timed out

How do I fix this error? Why is it specific to my computer?

If i use port 25 i get exception : Operation Timed out

If i use port 587 i get exception : The remote name could not be resolved: 'smtp.gmail.com'

if i use port 465 i get exception : Operation Timed out

Try some basic network troubleshooting. First, ensure you can ping something by IP address, this does not need DNS to work, so try ping 173.194.41.86 and see if you get some replies.

Then ping www.gmail.com from your machine with ping www.gmail.com. This should tell you if your network can resolve any names to IP addresses. You should get four IP address pings in the response the same as above.

If it does not, then your DNS configuration is bad. If you have a static IP address then you will need to check with a network admin or set the DNS servers the same as the working machine. If its dynamic then you might try ipconfig /renew to get the latest settings from the DHCP server.

If pinging www.gmail.com worked then try ping smtp.gmail.com to see if the smtp host is resolving. If it does not, then there's still a DNS issue but one that is effecting only the smtp hostname.

Try ipconfig /flushdns to clear the local DNS cache and try again. Try rebooting, if not on a prod server.

You can also use nslookup to check DNS name resolution and also Resolve-DnsName in PowerShell, possibly only in 3.0 though.

Also, check any firewall settings.