C#WinForms应用程序失败在发送电子邮件:远程名称无法解析:'smtp.gmail.com;操作超时 [英] C# Winforms Application Failure in sending Email: The remote name could not be resolved: 'smtp.gmail.com ; Operation Timed out

查看:69074
本文介绍了C#WinForms应用程序失败在发送电子邮件:远程名称无法解析:'smtp.gmail.com;操作超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WinForms C#程序发送电子邮件。我使用 MailMessage SmtpClient 。 在 SmtpClient 的构造函数中我通过 smtp.gmail.com 和端口587。

这是工作我的朋友的电脑上,但是当我尝试它,我得到这个错误:

  System.Net.Mail.SmtpException:失败发送邮件。 ---> System.Net.WebException:远程名称无法解析:smtp.gmail.com

System.Net.Mail.SmtpException:操作超时
 

如何解决这个问题?为什么具体到我的电脑?

 如果我使用25端口,我得到异常:操作超时

如果我使用端口587,我得到异常:远程名称无法解析:smtp.gmail.com

如果我使用端口465,我得到异常:操作超时
 

解决方案

尝试一些基本的网络故障排除。首先,确保你可以通过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.

这篇关于C#WinForms应用程序失败在发送电子邮件:远程名称无法解析:'smtp.gmail.com;操作超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆