【问题标题】:I got a error while sending mail using vb.net使用 vb.net 发送邮件时出错
【发布时间】:2017-06-13 19:26:48
【问题描述】:

错误是 SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应是: 5.7.0 必须首先发出 STARTTLS 命令。 t77sm26908892pfg.102 - gsmtp

          Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            SmtpServer.Credentials = New  _
        Net.NetworkCredential("user@gmail.com", "user1")
            mail = New MailMessage()
            mail.From = New MailAddress("user@gmail.com")

            mail.To.Add("user2@gmail.com")
            mail.Subject = "Test Mail"
            mail.Body = "This is for testing SMTP mail from GMAIL"
            SmtpServer.Send(mail)
            MsgBox("mail send")

【问题讨论】:

  • UseSSL true, theres a property to ssl;将其设置为 true...
  • 在我的代码中没有 ssl
  • 谢谢先生重播

标签: vb.net


【解决方案1】:

正如 Codexer 在他的评论中所说,您没有通过设置 SmtpServer.EnableSsl = True 来启用 SSL

Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Port = 587
SmtpServer.EnableSsl = True ' <---- this
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.Credentials = New  _
Net.NetworkCredential("user@gmail.com", "user1")
mail = New MailMessage()
mail.From = New MailAddress("user@gmail.com")
mail.To.Add("user2@gmail.com")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")

最好不要在互联网上以纯文本形式发送您的凭据...

【讨论】:

    猜你喜欢
    • 2018-02-18
    • 2014-09-15
    • 2012-01-16
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 2016-06-18
    • 2018-04-11
    • 1970-01-01
    相关资源
    最近更新 更多