Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
May 23

Written by: Steve Gray
5/23/2011 12:43 PM  RssIcon

This piece of code shows how to embed an image into an email using the System.Net.Mail namespace

  1. Try
  2.     Dim strServer As String = strMailServer
  3.  
  4.     Dim mail As New System.Net.Mail.MailMessage(strFrom, strTo)
  5.  
  6.     For Each cc In strCC.Split(";")
  7.         If cc > "" Then
  8.             mail.CC.Add(cc)
  9.         End If
  10.     Next
  11.  
  12.     For Each bcc As String In strBCC.Split(";")
  13.         If bcc > "" Then
  14.             mail.Bcc.Add(bcc)
  15.         End If
  16.     Next
  17.  
  18.     Dim htmlView As Net.Mail.AlternateView = Net.Mail.AlternateView.CreateAlternateViewFromString("Here is the image... <img src=cid:myImage>", Nothing, "text/html")
  19.  
  20.     Dim oImage As New Net.Mail.LinkedResource(strFilename)
  21.     oImage.ContentId = "myImage"
  22.     htmlView.LinkedResources.Add(oImage)
  23.  
  24.     mail.Subject = strSubject
  25.     mail.Body = strBody
  26.     mail.Priority = intPriority
  27.     mail.AlternateViews.Add(htmlView)
  28.  
  29.     Dim serv As New System.Net.Mail.SmtpClient(strServer)
  30.  
  31.     serv.Send(mail)
  32.  
  33. Catch ex As Exception
  34.     Throw New Exception(ex.Message)
  35. End Try

Tags:
Categories:
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us