Can't send email from my gmail acount using SmtpClient

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TobyMcGuire
    New Member
    • Mar 2010
    • 2

    Can't send email from my gmail acount using SmtpClient

    Using the code below I get an exception: "Failure sending mail"

    Inner exception: "No connection could be made because the target machine actively refused it 74.125.77.109:5 87"

    I'm currently on my office and behind a router. My firewall is turned off.
    The same situation occurs at home when behind my router with no firewall.

    When I set up an new acount in outlook with the same information as in the code below it works.

    I've also tried to connect to smtp.gmail.com using class TcpClient, but can't get a connection with exception: No connection could be made because the target machine actively refused it 74.125.77.109:5 87

    The funny thing is that when I'm run the exact same app att a computer connected to a 3G-router it works! This mean it has to something with my computer settings or the router at my office and home.

    Code:
    MailMessage mail = new MailMessage();
    mail.To.Add("me2@hotmail.com");
    mail.Subject = "subject";
    mail.From = new System.Net.Mail.MailAddress("me@gmail.com");
    mail.IsBodyHtml = false;
    mail.Body = "Body";
    
    SmtpClient smtp = new SmtpClient("smtp.gmail.com");
    smtp.Port = port;
    smtp.UseDefaultCredentials = false;
    smtp.EnableSsl = true;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new System.Net.NetworkCredential("me@gmail.com", "myPassword");
    
    smtp.Send(mail);
    Does anyone know where and how I have to configure to get this to work?
    Last edited by tlhintoq; Mar 17 '10, 02:46 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Trying using port 587 for sending.
      Lots of ISPs block the default port 25

      Comment

      • TobyMcGuire
        New Member
        • Mar 2010
        • 2

        #4
        I solved it myself. It was my virus protection, it prevented my computer from sending spam mails.

        Comment

        Working...