using System.Net.Mail To send smtp mail via google gets me a time out exception

Hey guys, I guess I got another question 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("");
    msg.Subject = "Re: Welcome to Tiamo";
    msg.Body = BodyMsg;

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

and this is my web.config email smtp settings:

  <smtp from="">
    <network host="" port="465" userName="" password="MyLovelyPassword" defaultCredentials="true"/>

Im completely exhausted so I thought the best thing is to pop up a question, hope you can help it will all be much appreciated... thanks anicho.


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

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

client.UseDefaultCredentials = false;

client.Credentials = new NetworkCredential("", "mypasswordforemail");

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


Need Your Help

Datatables one th with two filters inside


I have a specific design issue, I have an ththat have two filters, firstname and surname in the first th.

Refresh jquery object after ajax

javascript jquery ajax

I have a lucky spin script that need to get random number from database and let it spin to the number.