mail sending with network credential as true in windows form not working

gmail uses port 587

oClient.Port = 587;

You may also want to set UseDefaultCredentials to false and explicitly declare username and password. By declaring it to be true, you are trying to log into your gmail account using your windows credentials.

oClient.UseDefaultCredentials = false;
oClient.Credentials = new NetworkCredential("[email protected]", "password");

Also, in gmail security, you will need to allow Less Secure Applications.

Finally, you need to change how your Mail.To is populated:

oMail.To.Add(new MailAddress(txtTo.Text.Trim()));

Leave a Comment