【发布时间】:2023-04-01 11:59:01
【问题描述】:
我正在尝试生成一个电子邮件功能,它会向用户发送一封电子邮件,但是由于某种原因它无法正常工作并且它没有给出任何错误消息。
它只是弹出一个消息框,指出“此时出现问题。请稍后再试”。这是邮件发送失败时出现的消息框,但请您帮忙解决问题。
错误信息说
它说'发送电子邮件。 SMTP.Send(email)- System.dll 中出现“System.Net.Mail.SmtpException”类型的未处理异常附加信息:SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。了解更多信息 -
请查看下面的代码。
imports System.Net.Mail
Public Class EmailF
'assigns a new message to the email
Dim email As New MailMessage
'smtp is the server that has been used to send the email
Dim smtp As New SmtpClient
'assigns a new email address
Dim mail As System.Net.Mail.MailAddress
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'selects which email address to send the email from...
email.From = New MailAddress("blood4all.business@gmail.com")
email.Subject = SubBox.Text
email.Body = MessBox.Text
email.To.Add(ToBox.Text)
'the smtp outlook host.
Dim SMTP As New SmtpClient("smtp.gmail.com")
'the smtp port.
SMTP.Port = 587
SMTP.EnableSsl = True
'the login details for the gmail account.
SMTP.Credentials = New System.Net.NetworkCredential("blood4all.business@gmail.com", "Blood123")
'starts the progress bar.
Timer1.Start()
ProgressB.Show()
'sends the email.
SMTP.Send(email)
'pop up box conirms that the email has been sent.
MsgBox("The e-mail has been sent!")
Catch ex As Exception
MsgBox("There is a problem at this time. Please try again later")
ProgressB.Hide()
End Try
End Sub
异常信息是:
System.dll 中出现“System.Net.Mail.SmtpException”类型的未处理异常附加信息:SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。了解更多...
【问题讨论】:
-
注释掉 Try 行,Catch ex as exception 行和以下三行。重新运行代码,看看错误是什么。
-
它说'发送电子邮件。 SMTP.Send(email)- System.dll 中出现“System.Net.Mail.SmtpException”类型的未处理异常附加信息:SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应是:5.5.1 需要身份验证。了解更多信息
-
以防万一,但觉得有必要说一下 - 如果这是您的实际用户名/密码,您可能想现在更改该密码>.
-
@DavidWilson 请检查消息,这是身份验证问题而不是网络问题。此外,GMail 明确要求 587,并在其文档中非常清楚地解释了这一点
-
对于 ssl gmail 使用 465
标签: vb.net