Embed an image in an email

In the past I've just attached images that I send via System.Net.Mail, but I have a requirement today to embed the image so that it shows when the email text is viewed.     

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

Related Articles

... and you 'll find more on the NET Development Menu

            Dim strServer As String = strMailServer
 
            Dim mail As New System.Net.Mail.MailMessage(strFrom, strTo)
 
            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)

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences