gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:21:49 25 4
gpt4 key购买 nike

我们试图将 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("myEmailAddress@gmail.com", "myPassword")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True

ObjMailMessage = New MailMessage()

Try
ObjMailMessage.From = New MailAddress("myEmailAddress@gmail.com", "Some text is here.", System.Text.Encoding.UTF8)

ObjMailMessage.Subject = "Test message from Emad"
ObjMailMessage.ReplyToList.Add("john.doe@example.com")
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("john.doe@example.com")

最佳答案

您缺少收件人:地址,这会导致有关收件人的错误。

ObjMailMessage.To.Add(New MailAddress("mail@somemail.com", "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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com