Click here to Skip to main content
13,861,515 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


47 bookmarked
Posted 25 Mar 2009
Licenced CPOL

Sending Email Using Embedded Images

, 25 Mar 2009
Rate this:
Please Sign up or sign in to vote.
How to send embedded images in email using .NET 2.0.


Sending and receiving emails is a daily task for almost every professional, and programmers are not different. Sending emails and attachment is considered a trivial task, and all programming platforms support this feature.


You can send an email with images as external links, but most email clients block external links. There is another way around to send images as part of an email.

Using the code

The following code is self explanatory. Here, we go:

  1. Create a string that contains the HTML message to send.
  2. Create an AlternateView object for supporting the HTML.
  3. Create a LinkedResource object for the image to send.
  4. Add a LinkedResource object to the AlternateView object.
  5. Create a Mailmesasge object and set its To, From, and Subject properties.
  6. Add an AlternateView object to the MailMessage object.
  7. Create an SmtpClient object and send the MailMessage object.
using System.Net.Mail;

string htmlBody = "<html><body><h1>Picture</h1><br><img src=\"cid:Pic1\"></body></html>";
AlternateView avHtml = AlternateView.CreateAlternateViewFromString
    (htmlBody, null, MediaTypeNames.Text.Html);

// Create a LinkedResource object for each embedded image
LinkedResource pic1 = new LinkedResource("pic.jpg", MediaTypeNames.Image.Jpeg);
pic1.ContentId = "Pic1";

// Add the alternate views instead of using MailMessage.Body
MailMessage m = new MailMessage();

// Address and send the message
m.From = new MailAddress("", "Rizwan Qureshi");
m.To.Add(new MailAddress("", "Shayan Qureshi"));
m.Subject = "A picture using alternate views";
SmtpClient client = new SmtpClient("");

Points of interest

Since embedded images are part of emails, they can considerably increase the size of emails and can cause an email client to treat them as spam.


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


About the Author

Rizwan Qureshi
Chief Technology Officer Neuron Management Services
Pakistan Pakistan
I am a man with distinguish academic and professional career. i love programming and it is next to breathing to me. I did my post graduation in Computer Science and specialized in the field of Artificial Intelligence. these days i am busy in developing a developer friendly site. I am open to any suggestion and would definitely seek help in this regard.

Here are few Smile | :) certifications i earned:

MCPD Enterprise Application Development Framework 2.0
MCTS: Framwork Fundamentals 2.0
MCTS: Web Client Development 2.0
MCTS: Window Client Development 2.0
MCTS: Distributed Client Development 2.0

MCITP:Microsoft® SQL Server™ 2005 - Implementation and Maintenance

MCTS:Microsoft Windows SharePoint Services 3.0 - Application Development
MCTS:Developing Business Process and Integration Solutions using Microsoft® BizTalk® Server 2006
MCTS:Microsoft SQL Server 2005 Business Intelligence–Implementation and Maintenance

I wish my son would earn more certification when we celebrate his sixth birthday... Smile | :)

you can reach me at

You may also be interested in...


Comments and Discussions

SuggestionDispose Resources Pin
eferreyra16-Sep-16 4:54
membereferreyra16-Sep-16 4:54 
QuestionA long shot after 3 years but... Pin
John.Burke66626-Mar-16 16:10
memberJohn.Burke66626-Mar-16 16:10 
AnswerRe: A long shot after 3 years but... Pin
Garth J Lancaster26-Mar-16 17:52
professionalGarth J Lancaster26-Mar-16 17:52 
QuestionThe results not sufficient Pin
danies818-Jul-13 1:16
memberdanies818-Jul-13 1:16 
QuestionVery Useful Pin
Andy McNiece6-Jun-12 6:28
memberAndy McNiece6-Jun-12 6:28 
Questionnot work for thunderbird Pin
cyman_y8-Feb-12 23:14
membercyman_y8-Feb-12 23:14 
GeneralMy vote of 5 Pin
smnabil14-Jul-10 22:54
membersmnabil14-Jul-10 22:54 
GeneralMy vote of 3 Pin
Simon_Whale7-Jul-10 2:02
professionalSimon_Whale7-Jul-10 2:02 
GeneralIt works for attaching picture but not embedded them Pin
Hassaan Ahmed21-Nov-09 4:49
memberHassaan Ahmed21-Nov-09 4:49 
GeneralNice. You may have a look at... Pin
axuno25-Mar-09 10:20
memberaxuno25-Mar-09 10:20 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190214.1 | Last Updated 25 Mar 2009
Article Copyright 2009 by Rizwan Qureshi
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid