First Method:
Private Sub SendHtmlFormattedEmail(ByVal recepientEmail As String, ByVal subject As String, ByVal body As String)
Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage
Try
mailMessage.From = New MailAddress(ConfigurationManager.AppSettings("UserName"))
mailMessage.Subject = subject
mailMessage.Body = body
mailMessage.IsBodyHtml = True
mailMessage.To.Add(New MailAddress(recepientEmail))
Dim files As List(Of HttpPostedFile) = DirectCast(Cache(Me.Key), List(Of HttpPostedFile))
For Each file As HttpPostedFile In files
mailMessage.Attachments.Add(New Attachment(file.InputStream, Path.GetFileName(file.FileName), file.ContentType))
Next
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("[email protected]", "forgot123")
SMTP.Port = 587
SMTP.Send(mailMessage)
smtp.Send(mailMessage)
Catch ex As Exception
ex.Message.ToString()
End Try
End Sub
Second Method:
Private Sub SendEmail()
GetUserIDEmail(Session("LoggedInUserId"))
Dim Mail As New MailMessage
Mail.IsBodyHtml = True
Dim MailText As String = Nothing
'Dim attachment As System.Net.Mail.Attachment
Mail.Subject = " Report Submitted By : " & Session("LoggedInUserFullName") & " " & "User Type :" & GetUserTypeName(CInt(Session("UserTypes")))
MailText = MailText + "<font face='verdana' color='#000000'>" & "Dear User, " & "</font><br/><br/>" & Environment.NewLine
MailText = MailText + "<font face='verdana' color='#000000'>" + " " & "we are glad to inform you that your records has accepted.</font>" & "<br/> ""<font Face='Verdana' font-size:14px;Color='#000000'><b><br/>" + AcceptComments & """</font> " + Environment.NewLine
MailText = MailText + "<font Face='Verdana' font-size:14px;Color='#000000'><b><br/>" & " Regards," & " " & "<br/>" & "<i>Plan Pakistan RBME TEAM<i>" + "</b></font>" & vbCrLf
Mail.Body = MailText
Mail.Attachments.Add(New Attachment(file.InputStream, Path.GetFileName(file.FileName), file.ContentType))
Mail.From = New MailAddress("[email protected]")
SMTP.Send(Mail)