我们正在尝试发送了一个HTML字符串输出到一个特定的测试电子邮件地址发送电子邮件时,可以指定的错误,并发现此运行时错误:收件人必须从ASP.Net
A recipient must be specified.
这里是代码隐藏文件中的代码。
Protected Sub EmailTheList()
' Get the rendered HTML.
'-----------------------
Dim SB As New StringBuilder()
Dim SW As New StringWriter(SB)
Dim htmlTW As New HtmlTextWriter(SW)
GridViewSummary.RenderControl(htmlTW)
' Get the HTML into a string.
' This will be used in the body of the email report.
'---------------------------------------------------
Dim dataGridHTML As String = SB.ToString()
Dim SmtpServer As New SmtpClient()
SmtpServer.Credentials = New Net.NetworkCredential("[email protected]", "myPassword")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
ObjMailMessage = New MailMessage()
Try
ObjMailMessage.From = New MailAddress("[email protected]", "Some text is here.", System.Text.Encoding.UTF8)
ObjMailMessage.Subject = "Test message from Emad"
ObjMailMessage.ReplyToList.Add("[email protected]")
ObjMailMessage.Body = dataGridHTML
ObjMailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
SmtpServer.Send(ObjMailMessage)
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
我们怀疑我们没有使用正确的语法这一行:
ObjMailMessage.From = ObjMailMessage.ReplyToList.Add("[email protected]")
这是一个奇怪的错误,因为我已经设定的BCC列表。我想只有“To”被认为是规范的。 – arviman