I have a serious issue in sending email in C#. This is the code:
SmtpClient newSmpt = new SmtpClient()
{
Host = "smtp.googlemail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("mail@gmail.com", "password"),
Timeout = 30000
}
string body = 'html body';
String bodyEmail = email.Replace("@", "<span>@</span>");
bodyEmail = bodyEmail.Replace(".", "<span>.</span>");
body = body.Replace("<%email%>", bodyEmail);
body = body.Replace("<%name%>", name);
body = body.Replace("<%name%>", name);
MailMessage mailMessageMox = new MailMessage("mail@gmail.com", "info@mail.it", "Title", body);
mailMessageMox.IsBodyHtml = true;
newSmpt.Send(mailMessageMox);
With this code I managed to send mail correctly. Sometimes I catch an exception from the Send method with this message: "the smtp server requires a secure connection or the client was not authenticated". As you can see, the EnableSsl property is set to true, as told in other posts. When I go to gmail and try to login with the credentials used in the code, it asks me to enter a captcha code. After entering the captcha, I can login and then the code works fine. The problem is that this can happen too many times.
How to block captcha asking in gmail?