Click here to Skip to main content
Licence CPOL
First Posted 21 Aug 2007
Views 52,182
Downloads 829
Bookmarked 54 times

Send Inline Image Email (VB.NET 2.0)

By | 21 Aug 2007 | Article
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.
Prize winner in Competition "Best VB.NET article of Jul 2007"

Introduction

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

Background

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.

History

  • 22nd August, 2007: Initial post

License

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

About the Author

WPKF

Web Developer

Hong Kong Hong Kong

Member

A .NET Programmer for 8 years, who wants to share the experience.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
General.dat file as attachment Pinmemberdssohal13:53 7 Jul '09  
GeneralRe: .dat file as attachment PinmemberWPKF5:32 7 Jul '09  
GeneralMultiple images Pinmemberraquidd2220:12 5 May '09  
GeneralAwesome! PinmemberWillem_63623:08 5 Aug '08  
GeneralThank you! Pinmemberrobinnexus21:45 4 May '08  
GeneralPerfect PinmemberPhilM9916:08 4 Apr '08  
GeneralHere's someone else's solution Pinmemberwk6338:13 28 Aug '07  
GeneralRe: Here's someone else's solution Pinmemberpatelhirenn21:01 15 Jun '08  
GeneralYes but... PinmemberMaxHacker11:12 27 Aug '07  
Generaltest results PinmemberOhioStev1:10 23 Aug '07  
GeneralI attempted to use your code PinmemberOhioStev10:21 22 Aug '07  
GeneralRe: I attempted to use your code PinmemberWPKF17:18 22 Aug '07  
GeneralRe: I attempted to use your code PinmemberOhioStev1:44 23 Aug '07  
GeneralRe: I attempted to use your code PinmemberOhioStev4:41 23 Aug '07  
GeneralRe: I attempted to use your code PinmemberWPKF15:30 23 Aug '07  
GeneralNeat PinmemberBen Daniel19:43 21 Aug '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 22 Aug 2007
Article Copyright 2007 by WPKF
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid