Send SMTP message while debugging

Discussion in 'Email' started by PatrickCBrown, Feb 27, 2015.

  1. Hi

    I am unable to send automated email messages from my site while debugging locally, can you see what might be wrong with my approach? I get this error message: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

    var email = new System.Net.Mail.MailMessage()
    {
    Subject = "subject",
    From = new MailAddress("[email protected]")
    };

    email.To.Add("[email protected]");
    email.Body = "message";

    var smtp = new SmtpClient("smtp.MyDomain.com", 25);
    smtp.Credentials = new NetworkCredential("[email protected]", "password");
    smtp.Send(email);
     
  2. The hostname "smtp.MyDomain.com" that you're passing to the SmtpClient class constructor (or whatever the real hostname is that you're really passing) is failing to resolve. There's nothing wrong with this code. This is a networking / DNS resolution problem.
     
    mjp likes this.
  3. That's interesting, the exception shows it resolved to 64.79.170.143 (sm13.internetmailserver.net)
     
  4. Good to know that means the DNS part is actually working as it should. Which moves us onto:
    1. Port 25 is blocked either by a local firewall or by your ISP. Try using port 587 instead as mentioned here: https://support.discountasp.net/kb/...not-send-outgoing-mail.aspx?KBSearchID=557701
    2. The server wasn't available at the time when you ran your test (Unlikely / I'd expect to see some outage / maintenance post here if that was the case: http://community.discountasp.net/forums/outages-and-maintenance.34/)
     
    martino and mjp like this.
  5. The best thing to do is first test your own computer and local area network to see if the SMTP ports are open from the clients end. A simple and effect check is to simply run a telnet test to the mail servers specifying port 25 and 587. The email servers are configured to respond with a header.

    If you want to check if the ports are open on our end, use a 3rd party tool to check the ports. There are a lot of them online. The one I tend to use is http://ping.eu/port-chk/
    This will verify that the ports on our end are open. If you don't get the same results on your computer when you perform a telnet test, then it's an affirmation that something on your end maybe blocking or obstructing the necessary ports.
     
    CrystalCMS likes this.

Share This Page