Dim f As New StreamReader(My.Application.Info.DirectoryPath & "\htmlpage1.htm")
Dim HTML As String = f.ReadToEnd()
f.Close()
' (assuming that the file is in fact a template, at this point we probably will manipulate the text by replacing some placeholders by the current values)
Dim email As New System.Net.Mail.MailMessage("from-address","to-address")
email.Subject = "experts-exchange article"
email.Body = HTML
email.IsBodyHtml = True
Dim smtp As New SmtpClient
smtp.Host = "smtp-server-address"
smtp.Credentials = CredentialCache.DefaultNetworkCredentials
smtp.Send(email)
Things become more complicated when the HTML that we want to send includes an image. The easiest is to specify image source in HTML as a link to the external website hosting the image:
Dim f As New StreamReader(My.Application.Info.DirectoryPath & "\htmlpage1.htm")
Dim HTML As String = f.ReadToEnd()
f.Close()
Dim email As New System.Net.Mail.MailMessage("from-address","to-address")
email.Subject = "test"
email.Body = HTML
email.IsBodyHtml = True
email.Attachments.Add(New Attachment(My.Application.Info.DirectoryPath & "\logo.jpg"))
email.Attachments(0).ContentId = "logo_jpg"
Dim smtp As New SmtpClient
smtp.Host = "smtp-server-address"
smtp.Credentials = CredentialCache.DefaultNetworkCredentials
smtp.Send(email)
Dim PlainPart As String = "plain text representation"
email.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(PlainPart, New System.Net.Mime.ContentType("text/plain")))
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)