Cannot sent email from windows form application

Discussion in 'ASP.NET / ASP.NET Core' started by dbn10023, Dec 10, 2010.

  1. I get the following error message from the code below (note: av is turned off) where "HostedDomain" is my dasp domain - thanks in advance for any help.

    Message "Failure sending mail."
    InnerException {"Unable to connect to the remote server"} System.Exception {System.Net.WebException}


    MailMessage message = new MailMessage();
    MailAddress fromAddress = new MailAddress("[email protected]", "user name");

    message.From = fromAddress;
    message.To.Add("[email protected]");
    message.Subject = "subject";
    message.IsBodyHtml = false;
    message.Attachments.Add(new System.Net.Mail.Attachment(filename));

    SmtpClient mailClient = new SmtpClient();
    NetworkCredential credential = new NetworkCredential("[email protected]", "password");

    mailClient.Host = "smtp.HostedDomain.com";
    mailClient.UseDefaultCredentials = false;
    mailClient.Credentials = credential;

    mailClient.Send(message);
     
  2. ...Have you tried "localhost" as the host?
     

Share This Page