asp.net - 从 ASP.Net 发送电子邮件时必须指定收件人错误

标签 asp.net vb.net email

我们尝试将 html 字符串的输出发送到特定的测试电子邮件地址,并在运行时发现此错误:

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("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a17033f171b13163b1e1e081f09093a1d171b131654191517" rel="noreferrer noopener nofollow">[email protected]</a>", "myPassword")
    SmtpServer.Port = 587
    SmtpServer.Host = "smtp.gmail.com"
    SmtpServer.EnableSsl = True

    ObjMailMessage = New MailMessage()

    Try
        ObjMailMessage.From = New MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff9286ba929e9693be9b9b8d9a8c8cbf98929e9693d19c9092" rel="noreferrer noopener nofollow">[email protected]</a>", "Some text is here.", System.Text.Encoding.UTF8)

        ObjMailMessage.Subject = "Test message from Emad"
        ObjMailMessage.ReplyToList.Add("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b21242325652f242e0b2e332a263b272e65282426" rel="noreferrer noopener nofollow">[email protected]</a>")
        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("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="056f6a6d6b2b616a6045607d64687569602b666a68" rel="noreferrer noopener nofollow">[email protected]</a>")

最佳答案

您缺少“收件人:”地址,这导致出现有关收件人的错误。

ObjMailMessage.To.Add(New MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2bfb3bbbe92a1bdbfb7bfb3bbbefcb1bdbf" rel="noreferrer noopener nofollow">[email protected]</a>", "An error happened", System.Text.Encoding.UTF8))

引用:http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx

关于asp.net - 从 ASP.Net 发送电子邮件时必须指定收件人错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13607533/

相关文章:

asp.net - 使用 jQuery 查找 GridView 的特定列中是否选中了任何复选框

asp.net - 您可以配置 .Net 成员身份以使用 config/xml 文件作为数据源吗

c# - 更改所选控件的输入语言

asp.net - IE8 上快速播放的问题

mysql - 使用vb.net一键更新和插入mysql记录

mysql - 参数化查询显示 "Mixing named and unnamed parameters is not allowed."

.net - .net 中的对象引用和重新分配问题

PHP mail() 脚本向我发送不需要的电子邮件

php - 如何在邮件发送前清理 PHP 中的用户输入?

Jenkins 中基于脚本输出的电子邮件通知