将 Gridview 附加到电子邮件正文 VB.NET
Attatch Gridview to email body VB.NET
我目前正在我的网页中以编程方式发送电子邮件,电子邮件工作正常,但我还想将 gridview 附加到电子邮件正文中。
这是我的 VB 到目前为止用于发送电子邮件的代码...
Dim Uname As String = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\") + 1)
strFm = Uname + "@Inscapepeople.co.uk"
If strTo <> "" Then
Dim insMail As New System.Net.Mail.MailMessage(New MailAddress(strFm), New MailAddress(strTo))
With insMail
For Each y As String In strToREST.Split(";")
If y = "" Then
Else
.CC.Add(y)
End If
Next
.Subject = subject
.Body = Greet + "<br />" + "<br />" + bodyTxt.Text + "<br />" + PName + "- " + PNum + "<br />" + "<br />" + "The Required Date was: " + ReqDateNow.Text + " ,The Required Date is now: " + ReqDateAfter.Text + "<br />" + "Regards," + "<br />" + "<br />"
.IsBodyHtml = True
Sig = Uname
If Sig.ToLower = "djones" Then Sig = "GBennett"
Dim source As String = Path + Sig + ".jpg"
If System.IO.File.Exists(source) = False Then
Msgbox.ShowAlertMessage("Signature not found, but the email was still sent.")
Else
Dim lr As New LinkedResource(source)
lr.ContentId = "Signature"
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(insMail.Body + "<img width=""500"" height=""400"" src=cid:Signature>", Nothing, "text/html")
htmlView.LinkedResources.Add(lr)
.AlternateViews.Add(htmlView)
End If
End With
Dim smtp As New System.Net.Mail.SmtpClient
smtp.EnableSsl = False
smtp.Host = "192.168.50.2"
smtp.Port = 25
smtp.UseDefaultCredentials = True
smtp.Send(insMail)
我在网上搜索了一下,找不到任何可以帮助我的东西,我想知道我是否可以得到一些帮助,提前谢谢你。
如有任何帮助,我们将不胜感激。
我建议使用以下函数将 gridview 转换为 Html:
Private Function GridViewToHtml(ByVal gv As GridView) As String
Dim sb As New StringBuilder
Dim sw As New StringWriter
Dim hw As New HtmlTextWriter(sw)
gv.RenderControl(hw)
Return sb.ToString()
End Function
然后你可以调用这个函数并将它添加到你的电子邮件正文中。
我目前正在我的网页中以编程方式发送电子邮件,电子邮件工作正常,但我还想将 gridview 附加到电子邮件正文中。
这是我的 VB 到目前为止用于发送电子邮件的代码...
Dim Uname As String = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\") + 1)
strFm = Uname + "@Inscapepeople.co.uk"
If strTo <> "" Then
Dim insMail As New System.Net.Mail.MailMessage(New MailAddress(strFm), New MailAddress(strTo))
With insMail
For Each y As String In strToREST.Split(";")
If y = "" Then
Else
.CC.Add(y)
End If
Next
.Subject = subject
.Body = Greet + "<br />" + "<br />" + bodyTxt.Text + "<br />" + PName + "- " + PNum + "<br />" + "<br />" + "The Required Date was: " + ReqDateNow.Text + " ,The Required Date is now: " + ReqDateAfter.Text + "<br />" + "Regards," + "<br />" + "<br />"
.IsBodyHtml = True
Sig = Uname
If Sig.ToLower = "djones" Then Sig = "GBennett"
Dim source As String = Path + Sig + ".jpg"
If System.IO.File.Exists(source) = False Then
Msgbox.ShowAlertMessage("Signature not found, but the email was still sent.")
Else
Dim lr As New LinkedResource(source)
lr.ContentId = "Signature"
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(insMail.Body + "<img width=""500"" height=""400"" src=cid:Signature>", Nothing, "text/html")
htmlView.LinkedResources.Add(lr)
.AlternateViews.Add(htmlView)
End If
End With
Dim smtp As New System.Net.Mail.SmtpClient
smtp.EnableSsl = False
smtp.Host = "192.168.50.2"
smtp.Port = 25
smtp.UseDefaultCredentials = True
smtp.Send(insMail)
我在网上搜索了一下,找不到任何可以帮助我的东西,我想知道我是否可以得到一些帮助,提前谢谢你。
如有任何帮助,我们将不胜感激。
我建议使用以下函数将 gridview 转换为 Html:
Private Function GridViewToHtml(ByVal gv As GridView) As String
Dim sb As New StringBuilder
Dim sw As New StringWriter
Dim hw As New HtmlTextWriter(sw)
gv.RenderControl(hw)
Return sb.ToString()
End Function
然后你可以调用这个函数并将它添加到你的电子邮件正文中。