May
23
Written by:
Steve Gray
5/23/2011 12:43 PM
This piece of code shows how to embed an image into an email using the System.Net.Mail namespace
- Try
- Dim strServer As String = strMailServer
-
- Dim mail As New System.Net.Mail.MailMessage(strFrom, strTo)
-
- For Each cc In strCC.Split(";")
- If cc > "" Then
- mail.CC.Add(cc)
- End If
- Next
-
- For Each bcc As String In strBCC.Split(";")
- If bcc > "" Then
- mail.Bcc.Add(bcc)
- End If
- Next
-
- Dim htmlView As Net.Mail.AlternateView = Net.Mail.AlternateView.CreateAlternateViewFromString("Here is the image... <img src=cid:myImage>", Nothing, "text/html")
-
- Dim oImage As New Net.Mail.LinkedResource(strFilename)
- oImage.ContentId = "myImage"
- htmlView.LinkedResources.Add(oImage)
-
- mail.Subject = strSubject
- mail.Body = strBody
- mail.Priority = intPriority
- mail.AlternateViews.Add(htmlView)
-
- Dim serv As New System.Net.Mail.SmtpClient(strServer)
-
- serv.Send(mail)
-
- Catch ex As Exception
- Throw New Exception(ex.Message)
- End Try
As always, I welcome your comments!