【问题标题】:Sending Email VB.net Exception发送电子邮件 VB.net 异常
【发布时间】:2014-03-23 19:28:19
【问题描述】:

这是我的代码,它运行时没有错误但突然 出现异常 SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。

Dim smtpserver As New SmtpClient()
    Dim mail As New MailMessage()
    smtpserver.Credentials = New Net.NetworkCredential("myemail@gmail.com", "mypass")
    smtpserver.Host = "smtp.gmail.com"
    smtpserver.Port = "587"
    mail = New MailMessage
    mail.From = New MailAddress("myHouseHQ@gmail.com")
    mail.To.Add(Form2.TextBox1.Text)
    mail.Subject = "EagleEyes"
    mail.Body = "EagleEyes has detected a movement!"
    If emailphoto Then
        Dim attach As New Attachment("D:\hi" & sm & ".jpg")
        mail.Attachments.Add(attach)
    End If
    smtpserver.EnableSsl = True

    smtpserver.UseDefaultCredentials = False

    '   Try1
    smtpserver.Send(mail)
    'Catch ex As SmtpException
    'MsgBox("Error Connection!" & ex.Message)

    'End Try
    sm += 1

【问题讨论】:

  • 你试过阅读异常信息吗?您的凭据显然不正确

标签: vb.net email smtpclient


【解决方案1】:

不要在端口使用""。

请在端口上试试这个:

smtpserver.Port = 587

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 2010-12-24
    • 2014-01-06
    相关资源
    最近更新 更多