Geeks With Blogs
A Developer's Expedition
If you are like me it bugs you that users are forced to download images you placed in a html based email. Don't fret, you can embed the image and the user's will not be prompted to download images... 
HeaderInfo - needed for Outlook 2007; Not sure about 03...
AlternateView - Using a linked resource, this class embeds the linked resource in our case the image,
public boolSendEmailWithImage(stringMailToStr, stringMailFromStr, stringSubjectStr, stringBodyStr, stringImgPath)

string HeaderInfo = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:w=\"urn:schemas-microsoft-com:office:word\" xmlns:m=\"\" xmlns=\"\"><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=us-ascii\">";  


MailMessagemessage = newMailMessage(MailFromStr, MailToStr);
message.Subject = SubjectStr;
LinkedResource lr = newLinkedResource(ImgPath);
lr.ContentId = "Image"
AlternateView av = AlternateView.CreateAlternateViewFromString(HeaderInfo + BodyStr, null, MediaTypeNames.Text.Html);
av.TransferEncoding = TransferEncoding.QuotedPrintable;
message.IsBodyHtml = true;
SmtpClientclient = newSmtpClient(ConfigurationManager.AppSettings["MailServerSetting"].ToString(), 25); 
client.UseDefaultCredentials = true;
return true;
return false;
Posted on Sunday, November 2, 2008 8:52 PM | Back to top

Comments on this post: Embed image into email

# re: Embed image into email
Requesting Gravatar...
So it looks like this will load one image, correct? What would this look like if I had a rich/image-heavy HTML e-mail - is it as simple is looping through and instantiating LinkedResources? Just curious - may use this if that is the case :)

Cheers mate,
Left by SanjayU on Nov 03, 2008 7:23 PM

# re: Embed image into email
Requesting Gravatar...
cant we just copy paste?
Left by cep on Sep 16, 2009 5:48 PM

# re: Embed image into email
Requesting Gravatar...
simple way with automatic web tool
Left by pierluigi on Oct 12, 2010 8:57 AM

Your comment:
 (will show your gravatar)

Copyright © Ken Lovely, MCSE, MCDBA, MCTS | Powered by: