【问题标题】:Failure sending mail: {"The remote name could not be resolved: 'smtp.live.com'"}发送邮件失败:{“无法解析远程名称:'smtp.live.com'”}
【发布时间】:2017-08-20 04:37:48
【问题描述】:

我在过去 2 小时内尝试发送简单邮件时不断收到“无法解析远程名称:'smtp.live.com'”异常。 这是我的代码:

            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("someemail@outlook.com", "Some Name");
            mailMessage.To.Add(new MailAddress("someemail@domain.com"));
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = "<b>This is a check email</b>";
            mailMessage.Subject = "Test subject";

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Port = 587; //also tried 25 and 465
            smtpClient.Host = "smtp.live.com"; //also tried smtp-mail.outlook.com
            smtpClient.EnableSsl = true;
            smtpClient.UseDefaultCredentials = false; //also tried removing the credentials and setting this to true
            smtpClient.Credentials = new NetworkCredential("someemail@outlook.com", "its password");

            smtpClient.Send(mailMessage);

            Console.WriteLine("Success");

出于好奇,我尝试将 smtp.gmail.com 添加到主机并输入我的 gmail 凭据,但这也不起作用。这是跟踪:

System.Net.Mail.SmtpException was caught
  Message=Failure sending mail.
  Source=System
  StackTrace:
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at ConsoleApplication1.Program.Main(String[] args) in C:\Users\italha\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 95
  InnerException: System.Net.WebException
       Message=The remote name could not be resolved: 'smtp.live.com'
       Source=System
       StackTrace:
            at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
            at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
            at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
            at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
            at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpClient.GetConnection()
            at System.Net.Mail.SmtpClient.Send(MailMessage message)
       InnerException: 

以下是 nslookup 为我显示的 smtp.live.com 的内容:

我的互联网连接使用代理地址和端口 8080,是这个问题吗?请针对我的具体问题给出解决方案,我已经尝试了互联网上所有可用的通用解决方案。

【问题讨论】:

  • 您是否也在使用代理 smtp?
  • 您的邮件凭证有效吗?
  • 好吧,它甚至连尝试建立连接都没有解决IP - 所以很明显它花了太长时间才能解决..如果你可能/几乎肯定会遇到防火墙问题你有一个 http 代理,很可能端口没有开放让你的机器直接通话
  • @i.net 你知道我可以检查这个吗?我会检查防火墙设置。
  • Telnet 使用代理端口或更改您的代码以使用代理端口进行 smtp。此外,如果您无法使用其名称或 ip ping 服务器,则存在网络问题。

标签: c# visual-studio-2010 smtpclient mailmessage system.net.mail


【解决方案1】:

您的网络设置似乎有问题,或者防火墙阻止了邮件服务器。代码看起来不错。

尝试使用 trace ping 主机名,看看是否有效

【讨论】:

  • 是的,我向我的网络管理员询问了这个问题,他向我保证无法从我们的网络访问其他 smtp。他们被阻止了
  • 请将此标记为答案,以便将来遇到同样问题的人有所帮助。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-08
  • 1970-01-01
  • 2016-05-31
  • 2013-05-13
  • 1970-01-01
相关资源
最近更新 更多