I'm testing a normally working emailing module (.Net 4.5.2, C#) based on the System.Net.Mail.SmtpClient class, to which I have added support for TLS. To do this I'm trying to connect to my personal googlemail.com account using the same smtp settings that I use in my browser. I've set up the SmtpClient object as
SmtpClient mailer = new SmtpClient();
mailer.Host = "tls://smtp.gmail.com";
mailer.Credentials = new System.Net.NetworkCredential("me@googlemail.com","myGooglemailPassword"); mailer.EnableSsl = true;
mailer.UseDefaultCredentials = true; // although msdn states that this is necessary for TLS, it doesn't actually seeme to make any difference
mailer.Port = 587;
var message = new MailMessage();
message.Subject="dontcare";
message.Body = "dontcare"
message.To.Add("me@googlemail.com");
message.From = new MailAddress("myBusinessEmailaddress@somewhere");
mailer.Send(message);
The problem is that this is rejected by gmail with the error
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Given that my gmail account works normally for me otherwise, what am I missing in the .Net implementation?