Failure sending mail (using Gmail Service) RRS feed

  • Question

  • User944339287 posted

    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"
                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)))
                        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
                    If attachment IsNot Nothing Then
                    End If
                    success = True
                End Using
            Catch ex As Exception
            End Try
            ' end try 
            Return success
        End Function

    Tuesday, February 2, 2021 8:38 AM

All replies