Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Why won't an embedded image show in html emails?

I'm looking to embed a header image into an HTML email generated by c#.  I've found code that is supposed to work, but the email arrives with the usual red x saying that it has no image.  (The same happens in Hotmail).  However, if I forward it, the attachment appears and so does the image.  Any ideas what might be going wrong?
if (EmailType == "ConfirmRegistration")
        {
            message.IsBodyHtml = true;
            string contentId = "headerImage";
            string path = HttpContext.Current.Server.MapPath(@"img/Email/Header.jpg");
            LinkedResource header = new LinkedResource(path, MediaTypeNames.Image.Jpeg);
            header.ContentId = "header";
            AlternateView av1 = AlternateView.CreateAlternateViewFromString("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns=\"urn:schemas-microsoft-com:office:office\" xmlnso=\"urn:schemas-microsoft-com:office:word\" xmlns:m=\"http://schemas.microsoft.com/office/2004/12/omml\" xmlns=\"http://www.w3.org/TR/REC-html40\"><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=us-ascii\"><body><img src=cid:header/><br></body></html>" + sEmailBody, null, MediaTypeNames.Text.Html);
            av1.LinkedResources.Add(header);
            message.AlternateViews.Add(av1);
        }
        smtpClient.Send(message);

Open in new window

Email.JPG
HotmailforwardedEmail.JPG
0
mkingshott
Asked:
mkingshott
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
can you test if the example from http://www.emoreau.com/Entries/Articles/2007/09/Using-SystemNetMail.aspx is working for you (because it is for me)
0
 
Anurag ThakurCommented:
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now