Click here to Skip to main content
16,022,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
Good day.
I have a project in VB.net, its a windows form application.
All is good, but i could not send email without involving outlook. System gives the following error ....

"
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. For more information, go to
"

Can anyone highlight what kind of mistake i am doing.

The code that i wrote is ............

What I have tried:

Public Sub Send_Email_SMTP()
       Try
           Dim SmtpServer As New SmtpClient()
           SmtpServer.UseDefaultCredentials = False
           SmtpServer.EnableSsl = True
           Dim mail As New MailMessage()
           SmtpServer.Credentials = New _
           Net.NetworkCredential("from@gmail.com", "password")
           SmtpServer.Port = 587
           SmtpServer.Host = "smtp.gmail.com"
           mail = New MailMessage()
           mail.From = New MailAddress("from@gmail.com")
           mail.To.Add("to@gmail.com")
           mail.Subject = "My Email Subject"
           mail.Body = "My Email Body"
           SmtpServer.Send(mail)
           MsgBox("Email has been sent")
       Catch ex As SmtpException
           MessageBox.Show(ex.Message, "Send_Email_SMTP", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
       End Try
End Sub
Posted

You cannot use your GMail credentials for sending email. Instead, you need to create an "app password" and use that instead.

Sign in with app passwords - Google Account Help[^]

Alternatively, you can use MailKit[^] and OAuth2:
MailKit/GMailOAuth2.md at master · jstedfast/MailKit · GitHub[^]
 
Share this answer
 
v2
Google blocks what it thinks are insecure apps. You need to set Less Secure Sign-In or Less secure app access for your app inside your Google account. See Less Secure App Access[^] for more information.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900