Hi guys.. i getting this error while trying to send an email via smtp.gmail.com The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at
The following is my code for sending emails out.
sender@hello.com is a Google business email account.
This web application is parked at www.byebye.com which let system user send an email out.
Anything wrong to my code or setting?
Public Function SendEmail() As Boolean
Dim success As Boolean = False
'Recipient email
Dim [to] As String = "receiver@gmail.com"
Dim cc As String = ""
Dim bcc As String = ""
'Sender email
Dim from As String = "sender@hello.com"
'Sender account
Dim fromName As String = "HELLO WORLD"
Dim userName As String = "sender@hello.com"
Dim password As String = "fd##4jhAbWQ"
Dim attachment As Attachment = Nothing
Dim client As New SmtpClient()
client.EnableSsl = "True"
client.Credentials = New System.Net.NetworkCredential(userName, password)
client.Port = "587"
client.Host = "smtp.gmail.com"
Try
Using mail As New MailMessage()
mail.From = New MailAddress(from, fromName)
mail.ReplyTo = New MailAddress("sender@hello.com")
mail.Sender = mail.ReplyTo
If [to].Contains(";") Then
Dim _EmailsTO As String() = [to].Split(";".ToCharArray())
For i As Integer = 0 To _EmailsTO.Length - 1
mail.[To].Add(New MailAddress(_EmailsTO(i)))
Next
Else
If Not [to].Equals(String.Empty) Then
mail.[To].Add(New MailAddress([to]))
End If
End If
mail.Subject = "Testing Mail from Gmail Server"
mail.SubjectEncoding = System.Text.Encoding.UTF8
mail.Body = "HELLO WORLD"
mail.IsBodyHtml = True
mail.BodyEncoding = System.Text.Encoding.UTF8
'attachment
If attachment IsNot Nothing Then
mail.Attachments.Add(attachment)
End If
client.Send(mail)
success = True
End Using
Catch ex As Exception
End Try
' end try
Return success
End Function
Google may block sign in attempts from some apps or devices that do not use modern security standards. Since these apps and devices are easier to break into, blocking them helps keep your account safer.
For example, some third-party applications such as desktop mail clients ( such as Microsoft Outlook ,Mozilla Thunderbird,etc).
Therefore, you have to enable Less Secure Sign-In (or Less secure app access) in your google account.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
103 Points
793 Posts
Failure sending mail (using Gmail Service)
Feb 02, 2021 08:38 AM|kengkit|LINK
Hi guys.. i getting this error while trying to send an email via smtp.gmail.com
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at
The following is my code for sending emails out. sender@hello.com is a Google business email account.
This web application is parked at www.byebye.com which let system user send an email out.
Anything wrong to my code or setting?
Contributor
2090 Points
668 Posts
Re: Failure sending mail (using Gmail Service)
Feb 03, 2021 03:30 AM|XuDong Peng|LINK
Hi kengkit,
Google may block sign in attempts from some apps or devices that do not use modern security standards. Since these apps and devices are easier to break into, blocking them helps keep your account safer.
For example, some third-party applications such as desktop mail clients ( such as Microsoft Outlook ,Mozilla Thunderbird,etc).
Therefore, you have to enable Less Secure Sign-In (or Less secure app access) in your google account.
After sign into google account, go to ---> https://www.google.com/settings/security/lesssecureapps
You could also refer to this similar case:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required?
Best regards,
Xudong Peng