3

I am trying to send email using smtp authentication through google but I am constantly getting a timed out error and no idea what it might be from the following code its not my firewall or my isp blocking smtp ports so its most probably the code:

    MailMessage msg = new MailMessage();

    String BodyMsg;

    BodyMsg = "Hey " + TxtBoxUsername.Text + "@" + "Welcome to Tiamo your username and password are:@Username: "
        + TxtBoxUsername.Text + "@Password: " + PasswordString + "@You have succesffully registered, you can now login."
        + "@Thank You@Tiamo Team";

    BodyMsg = BodyMsg.Replace("@", System.Environment.NewLine);

    msg.To.Add(new MailAddress(TxtBoxEmail.Text));
    msg.From = new MailAddress("someemail@emailme.com");
    msg.Subject = "Re: Welcome to Tiamo";
    msg.Body = BodyMsg;

    SmtpClient client = new SmtpClient() ;
    client.EnableSsl = true;                                  
    client.Send(msg); 

and this is my web.config email smtp settings:

  <system.net>
    <mailSettings>
      <smtp from="someemail@myemail.com">
        <network host="smtp.gmail.com" port="465" userName="someemail@myemail.com" password="MyLovelyPassword" defaultCredentials="true"/>
      </smtp>
    </mailSettings>
  </system.net>
Anicho
  • 2,647
  • 11
  • 48
  • 76

2 Answers2

3

I'm affraid google uses another port -> 587 or at least that's what they tell on their configure-gmail-access-in-outlook-help-website

Gambrinus
  • 2,140
  • 16
  • 26
  • Yes this worked am getting a: The SMTP server requires a secure connection or the client was not authenticated. Any idea my google credentials are deffo correct – Anicho Apr 16 '10 at 10:57
  • http://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c its cool this fixed it – Anicho Apr 16 '10 at 11:07
1

In my case it was the order of the following code lines:

client.UseDefaultCredentials = false;

client.Credentials = new NetworkCredential("myaddress@gmail.com", "mypasswordforemail");

As it may seem logical, UseDefaultCredentials=false; should go first.

Regards.

danfer
  • 371
  • 1
  • 3
  • 10