我們正在嘗試發送了一個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