Click here to Skip to main content
14,302,993 members

Send Inline Image Email (VB.NET 2.0)

Rate this:
4.19 (9 votes)
Please Sign up or sign in to vote.
4.19 (9 votes)
21 Aug 2007CPOL
Send HTML Email with embedded image files instead of external link. Most email client will display inline image directly since there is less security risk. No more broken images.


This solution is to demonstrate how to send HTML with an embedded image file. This solution should extend to include any non-text object.


I receive a lot of email from friends with broken links or images. This is because many email clients or Web mail providers block external images (i.e. referencing images hosted on other domain / servers). I feel it is annoying since it requires me to manually adjust the spam filter or add the sender as safe.

Using the Code

Download the zip file and open the solution. The code is easy to read and understand.

Please note that all fields are required. You can add your own code for validation or preset value.

' The main trick is to use ContentId to reference the attachment
        Dim A As System.Net.Mail.Attachment = _
            New System.Net.Mail.Attachment(txtImagePath.Text)
        Dim RGen As Random = New Random()
        A.ContentId = RGen.Next(100000, 9999999).ToString()
        EM.Body = "<img src='cid:" + A.ContentId +"'>" 

Points of Interest

Please be considerate to the recipients, if your image is very large (in terms of file size), it is still better to send HTML using external images. Don't blow up their mailbox! Otherwise, you will be added to their 'spam sender' list.

This is my first contribution to The Code Project. I tried to search for related topics but failed. Hope it is helpful to you.


  • 22nd August, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Hong Kong Hong Kong
A .NET Programmer for 8 years, who wants to share the experience.

Comments and Discussions

GeneralWorks well .NET Framework 4 Pin
robnick15-Jun-12 18:37
memberrobnick15-Jun-12 18:37 
General.dat file as attachment Pin
dssohal17-Jul-09 3:53
memberdssohal17-Jul-09 3:53 
GeneralRe: .dat file as attachment Pin
WPKF7-Jul-09 5:32
memberWPKF7-Jul-09 5:32 
GeneralMultiple images Pin
raquidd225-May-09 20:12
memberraquidd225-May-09 20:12 
GeneralAwesome! Pin
Willem_6365-Aug-08 23:08
memberWillem_6365-Aug-08 23:08 
GeneralThank you! Pin
roninnexus4-May-08 21:45
memberroninnexus4-May-08 21:45 
GeneralPerfect Pin
PhilM994-Apr-08 16:08
memberPhilM994-Apr-08 16:08 
GeneralHere's someone else's solution Pin
wk63328-Aug-07 8:13
memberwk63328-Aug-07 8:13 
GeneralRe: Here's someone else's solution Pin
patelhirenn15-Jun-08 21:01
memberpatelhirenn15-Jun-08 21:01 
GeneralYes but... Pin
MaxHacker27-Aug-07 11:12
memberMaxHacker27-Aug-07 11:12 
Generaltest results Pin
OhioStev23-Aug-07 1:10
memberOhioStev23-Aug-07 1:10 
GeneralI attempted to use your code Pin
OhioStev22-Aug-07 10:21
memberOhioStev22-Aug-07 10:21 
GeneralRe: I attempted to use your code Pin
WPKF22-Aug-07 17:18
memberWPKF22-Aug-07 17:18 
GeneralRe: I attempted to use your code Pin
OhioStev23-Aug-07 1:44
memberOhioStev23-Aug-07 1:44 
GeneralRe: I attempted to use your code Pin
OhioStev23-Aug-07 4:41
memberOhioStev23-Aug-07 4:41 
GeneralRe: I attempted to use your code Pin
WPKF23-Aug-07 15:30
memberWPKF23-Aug-07 15:30 
GeneralNeat Pin
Ben Daniel21-Aug-07 19:43
memberBen Daniel21-Aug-07 19:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 21 Aug 2007


56 bookmarked