title: Unable to send email from web application
body: <p>I've looked this up and it seems other people have had the same issue mainly because Gmail was blocking the application's access, however I've turned on the "allow less secure apps to connect" option and the problem remains.</p>
  
  <p>Here's the complete error message I get from ASP.net when I try to connect. </p>
  
  <p><code>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</code></p>
  
  <p>I've tried connecting using port 465 and I get a time-out (I assumed it was the Explicit/Implicit SSL problem)</p>
  
  <p>Here's the code that I'm using to send the emails.</p>
  
  <pre><code>Dim Mail As New MailMessage
      Dim EmailToMail As New MailAddress(EmailTo, EmailToName)
      Mail.To.Add(EmailToMail)
      Dim FromE As New MailAddress(EmailFrom, "Something")
      Mail.From = FromE
      Mail.Body = Body
      Mail.Subject = Title
  
      Dim SmtpClient As New SmtpClient("smtp.gmail.com", 587)
  
      SmtpClient.UseDefaultCredentials = False
      Dim SmtpCredentials As New System.Net.NetworkCredential("MyEmail", "MyPassword")
      SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
      SmtpClient.EnableSsl = True
  
      SmtpClient.Send(Mail)
  </code></pre>
  
  <p>I've also tried setting UseDefaultCredentials to True, which didn't work.</p>