0

so I've been trying to set up a contact form using google's smtp server but im having the error written in the title. I've tried to look up for solutions online and I have already changed my password to a strong one, I disabled the gmail account's security, I logged in from the server's web browser onto the gmail account. Any ideas on how I can solve this?

    Dim strFrom = "EMAIL@gmail.com"
    Dim strTo = "RECEPIENT@EMAIL.net"
    Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo))
    MailMsg.BodyEncoding = Encoding.Default
    MailMsg.Subject = "This is a test"
    MailMsg.Body = "This is a sample message using SMTP authentication"
    MailMsg.Priority = MailPriority.High
    MailMsg.IsBodyHtml = True
    'Smtpclient to send the mail message 

    Dim SmtpMail As New SmtpClient
    Dim basicAuthenticationInfo As New System.Net.NetworkCredential("EMAIL@gmail.com", "PASSWORD")

    SmtpMail.Host = "smtp.gmail.com"
    SmtpMail.Port = "587"
    SmtpMail.UseDefaultCredentials = False
    SmtpMail.Credentials = basicAuthenticationInfo

    SmtpMail.Send(MailMsg)
John Doe
  • 15
  • 6
  • Possible duplicate of [Sending email through Gmail SMTP server with C#](https://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c-sharp) – mason Jun 28 '17 at 17:28
  • Possible duplicate of [Sending email in .NET through Gmail](https://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail) – VDWWD Jun 28 '17 at 19:11

1 Answers1

0

You are so close.

You need to add the following setting for it to work:

   smtpMail.enabledssl = true
WonderWorker
  • 7,388
  • 3
  • 52
  • 71
John Doe
  • 15
  • 6