简体   繁体   English

发送邮件失败:{“无法解析远程名称:'smtp.live.com'”}

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

I am getting the "The remote name could not be resolved: 'smtp.live.com'" exception continuously from the past 2 hours while trying to send a simple mail.在尝试发送简单邮件时,我在过去 2 小时内不断收到“无法解析远程名称:‘smtp.live.com’”异常。 Here is my code:这是我的代码:

            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");

Just out of curiosity, i have tried adding the smtp.gmail.com to the host and entering my gmail credentials as well, but that didn't work either.出于好奇,我尝试将 smtp.gmail.com 添加到主机并输入我的 gmail 凭据,但这也没有用。 Here's the trace:这是踪迹:

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: 

Here is what nslookup shows me for smtp.live.com:这是 nslookup 向我显示的 smtp.live.com 的内容: 在此处输入图像描述

My internet connection uses a proxy address and a port 8080, is that the problem?我的互联网连接使用代理地址和端口 8080,这是问题所在吗? Please give solution for my specific problem, i have already tried all the general solutions available on internet as of yet.请针对我的具体问题提供解决方案,到目前为止,我已经尝试了互联网上所有可用的通用解决方案。

Looks like there is an issue with your network settings or the firewall is blocking the mailing server.看起来您的网络设置有问题,或者防火墙阻止了邮件服务器。 The code seems fine.代码看起来不错。

Try to ping the hostname with trace and see if that works尝试使用 trace ping 主机名,看看是否可行

I am getting the "The remote name could not be resolved: 'smtp.live.com'" exception continuously from the past 2 hours while trying to send a simple mail.在尝试发送简单邮件时,我在过去 2 小时内不断收到“无法解析远程名称:'smtp.live.com'”异常。 Here is my code:这是我的代码:

            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");

Just out of curiosity, i have tried adding the smtp.gmail.com to the host and entering my gmail credentials as well, but that didn't work either.出于好奇,我尝试将 smtp.gmail.com 添加到主机并输入我的 gmail 凭据,但这也不起作用。 Here's the trace:这是跟踪:

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: 

Here is what nslookup shows me for smtp.live.com:以下是 nslookup 向我展示的 smtp.live.com: 在此处输入图片说明

My internet connection uses a proxy address and a port 8080, is that the problem?我的互联网连接使用代理地址和端口 8080,这是问题吗? Please give solution for my specific problem, i have already tried all the general solutions available on internet as of yet.请给出我的具体问题的解决方案,到目前为止,我已经尝试了互联网上所有可用的通用解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM