Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

后端 未结 25 2404
悲&欢浪女
悲&欢浪女 2020-11-22 02:12

I am using following code to send email. The Code works correctly in my local Machine. But on Production server i am getting the error message

var fromAddres         


        
25条回答
  •  情深已故
    2020-11-22 03:00

    What worked for me was to activate the option for less secure apps (I am using VB.NET)

    Public Shared Sub enviaDB(ByRef body As String, ByRef file_location As String)
            Dim mail As New MailMessage()
            Dim SmtpServer As New SmtpClient("smtp.gmail.com")
            mail.From = New MailAddress("from@gmail.com")
            mail.[To].Add("to@gmail.com")
            mail.Subject = "subject"
            mail.Body = body
            Dim attachment As System.Net.Mail.Attachment
            attachment = New System.Net.Mail.Attachment(file_location)
            mail.Attachments.Add(attachment)
            SmtpServer.Port = 587
            SmtpServer.Credentials = New System.Net.NetworkCredential("user", "password")
            SmtpServer.EnableSsl = True
            SmtpServer.Send(mail)
        End Sub
    

    So log in to your account and then go to google.com/settings/security/lesssecureapps

提交回复
热议问题