Search code examples
c#visual-studio-2010smtpclientmailmessagesystem.net.mail

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. Here is my code:

            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("[email protected]", "Some Name");
            mailMessage.To.Add(new MailAddress("[email protected]"));
            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("[email protected]", "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. 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: enter image description here

My internet connection uses a proxy address and a port 8080, is that the problem? Please give solution for my specific problem, i have already tried all the general solutions available on internet as of yet.


Solution

  • 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