在Web应用程序中发送电子邮件

时间:2016-11-10 09:37:35

标签: asp.net vb.net smtpclient

我试图在点击按钮后发送电子邮件。但这是我得到的例外

enter image description here

我的代码有问题吗?我已经尝试进入我的Gmail设置并打开“访问不太安全的应用程序”,仍然存在问题。

.tooltip.top .tooltip-arrow:after {
  content: " ";
  position: absolute;
  width: 0;
  height: 0;
  border-color: transparent;
  border-style: solid;
  left: -17px;
  top: -5px;
  border-width: 12px;
  border-top-color: #003f6e;
  border-bottom:none;
}
.tooltip.top .tooltip-arrow:before {
  content: " ";
  position: absolute;
  width: 0;
  height: 0;
  border-color: transparent;
  border-style: solid;
  left: -15px;
  top: -5px;
  border-width: 10px 10px 0;
  border-top-color: #fff;
  border-bottom:none;
  z-index: 1;
}

Imports System.Net.Mail Imports System.Net Partial Class _Default Inherits System.Web.UI.Page` Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click Try Dim mailMessage As New MailMessage("group2@gmail.com", "ndumisosizwe@gmail.com") mailMessage.Subject = "Mail Body" mailMessage.Body = "This is a test email" Dim SmtpClient As New SmtpClient("smtp.gmail.com", 587) Dim credentials As New NetworkCredential("group2@gmail.com", "myPasswordHere") SmtpClient.Credentials = credentials SmtpClient.EnableSsl = True SmtpClient.Send(mailMessage) MsgBox("Email sent successfully") Catch ex As Exception MsgBox("Email Failed ! " & ex.ToString) End Try End Sub End Class

上抛出异常

1 个答案:

答案 0 :(得分:0)

根据此page,您使用的端口用于TLS。 SSL(旧版本)的端口是465。

也许EnableSsl不支持TLS。您可以尝试使用该端口。