VB.NET SMTP gmail无法正常工作

时间:2015-02-23 17:12:54

标签: vb.net smtp gmail

我一直收到此错误消息 任何解决方案

" smtp服务器需要安全连接或客户端未经过身份验证5.5.1"

Public Sub SendCode()

    GenerateCode()

    Dim Mail As New MailMessage
    Dim SMTPServer As New SmtpClient("smtp.gmail.com")
    Try
        SMTPServer.Credentials = New  _
       Net.NetworkCredential("email@gmail.com", "password")
        Mail.From = New MailAddress("email@gmail.com")
        Mail.To.Add("email2@gmail.com")
        Mail.Subject = "Confirmation Code"
        Mail.Body = Me.Firstname & " " & Me.LastN & " This is a NO_REPLY confirmation Email, Confirmation Code:" & Me.ConfirmationCode & ""
        SMTPServer.Port = 587
        SMTPServer.EnableSsl = True
        SMTPServer.Send(Mail)
        MsgBox("mail sent")
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

1 个答案:

答案 0 :(得分:1)

您需要将端口设置为465,将SSL / TLS设置为自动...

我已成功使用此代码... https://www.emailarchitect.net/easendmail/kb/vbnet.aspx?cat=2