发送邮件失败:{"The remote name could not be resolved: 'smtp.live.com'"}

Failure sending mail: {"The remote name could not be resolved: 'smtp.live.com'"}

我在过去 2 小时内尝试发送一封简单的邮件时不断收到 "The remote name could not be resolved: '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,这是问题所在吗?请针对我的具体问题给出解决方案,到目前为止我已经尝试了互联网上所有可用的通用解决方案。

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

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