このコーディングを使用して、ASP.NetコードビハインドVb.Netファイルから電子メールを送信しています。
このコーディングのいずれかをWeb.configファイル内に配置できますか?
Protected Sub EmailStudentList()
' 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("ourEmailUsername@gmail.com", "ourPassword")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
ObjMailMessage = New MailMessage()
Try
ObjMailMessage.From = New MailAddress("ourEmail@gmail.com", "Some text is here.", System.Text.Encoding.UTF8)
ObjMailMessage.To.Add(New MailAddress("BoardOfDirectors@gmail.com", "Emad-ud-deen", System.Text.Encoding.UTF8))
ObjMailMessage.Subject = "List of enrolled students for the board of directors"
ObjMailMessage.Body = dataGridHTML
ObjMailMessage.IsBodyHtml = True
ObjMailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
SmtpServer.Send(ObjMailMessage)
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub