1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| 'Get the report
Dim report As New SUSReportsFactory
Dim gridReportHTML As GridView = report.GetDataGridFromDataTable(report.SelectReportByServerPatchingForHTMLMail(275, 22))
Dim htmlView As AlternateView
'PLAIN VIEW
'Dim gridReportPlain As GridView = report.GetDataGridFromDataTable(report.SelectReportByServerPatchingForPlainMail(275, 22))
'Dim stringMailContentPlain As String = GridViewToHtml(gridReportPlain)
Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString("Canot display Gridview in HTML", Nothing, "text/plain")
' HTML VIEW
Dim stringMailContentHTML As String = GridViewToHtml(gridReportHTML)
stringMailContentHTML = stringMailContentHTML.Replace("<", "<")
stringMailContentHTML = stringMailContentHTML.Replace(">", ">")
htmlView = AlternateView.CreateAlternateViewFromString(stringMailContentHTML, Nothing, "text/html")
Dim err As New LinkedResource("E:\BetaMom\img\Error-32x32.png")
err.ContentId = "err"
err.TransferEncoding = TransferEncoding.Base64
Dim info As New LinkedResource("E:\BetaMom\img\InfoBox-32x32.png")
info.ContentId = "info"
info.TransferEncoding = TransferEncoding.Base64
Dim warning As New LinkedResource("E:\BetaMom\img\Warning-32x32.png")
warning.ContentId = "warning"
warning.TransferEncoding = TransferEncoding.Base64
'add the LinkedResource to the appropriate view
htmlView.LinkedResources.Add(err)
htmlView.LinkedResources.Add(info)
htmlView.LinkedResources.Add(warning)
'Public Sub sendMail(ByVal userMail As MailAddress, ByVal server As SUSServer)
Dim mail As MailMessage = New MailMessage
mail.AlternateViews.Add(plainView)
mail.AlternateViews.Add(htmlView)
mail.From = New MailAddress("aaa@aaa.com", "ssss")
mail.To.Add("aaa@aaa.com")
mail.Sender = New MailAddress("aaa@aaa.com", "ssss")
mail.ReplyTo = New MailAddress("aaa@aaa.com", "ssss")
mail.Subject = "SUS"
mail.Attachments.Clear()
Dim smtpCli As SmtpClient = New SmtpClient("xxx")
smtpCli.Send(mail)
End Sub
Private Function GridViewToHtml(ByVal gv As GridView) As String
Dim sb As StringBuilder = New StringBuilder()
Dim sw As StringWriter = New StringWriter(sb)
Dim hw As HtmlTextWriter = New HtmlTextWriter(sw)
gv.RenderControl(hw)
Return sw.ToString()
End Function |
Partager