.NET 2.0 SMTP client HELP: Embedded images show up as red X in the message

I have a problem with seeing the embedded images in a html formatted message. Here is the setup info. Everything is on a single box, a typical dev environment

Server

Windows Server 2003 /IIS 6/SMTP Virtual  Server/ASP.NET 2.0/ system.net.mail

Client

Outlook 2003

I am wondering why the Outlook client doesn't display the image inline but when I reply or forward the message, I can see the Image in the message.. Where is the blocking happening and why is my client not able to decode HTML formatted message correctly..

 

Here is the mail header

 

Microsoft Mail Internet Headers Version 2.0
Received: from box.domain.com ([10.1.14.116]) by exchangeserver.domain.com with Microsoft SMTPSVC(6.0.3790.1830);
  Fri, 16 Dec 2005 21:53:25 -0600
Received: from sivas ([127.0.0.1]) by box.domain.com with Microsoft SMTPSVC(6.0.3790.1830);
  Fri, 16 Dec 2005 21:51:24 -0600
mime-version: 1.0
from: "user@domain.com" <user@domain.com>
sender: user@domain.com
to: user@domain.com
date: 16 Dec 2005 21:51:24 -0600
subject: Check your report
content-type: multipart/related;
 boundary=--boundary_5_3088b236-573d-427a-a7df-8fd3904f3e58; type="text/html"
Return-Path: user@domain.com
Message-ID: <BOXNAMERaqbC8wSA1XvpF00000007@box.domain.com>
X-OriginalArrivalTime: 17 Dec 2005 03:51:24.0051 (UTC) FILETIME=[26410E30:01C602BD]

----boundary_5_3088b236-573d-427a-a7df-8fd3904f3e58
content-type: text/html; charset=utf-8
content-transfer-encoding: quoted-printable

----boundary_5_3088b236-573d-427a-a7df-8fd3904f3e58
content-type: image/jpeg
content-transfer-encoding: base64
content-id: <image1>


----boundary_5_3088b236-573d-427a-a7df-8fd3904f3e58--

 

 

Here is a C# code snippet to send the mail

m.IsBodyHtml = true;

AlternateView av = AlternateView.CreateAlternateViewFromString(string.Format("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body><div id=\"message\"><font color=\"#333333\" size=\"2\">{0}</font></div><br/> <img src=\"cid:image1\"/></body></html>", message.Text.Replace("\n", "<BR/>")), null, System.Net.Mime.MediaTypeNames.Text.Html);

av.ContentType.MediaType = "text/html";

av.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;

MemoryStream ms = new MemoryStream(File.ReadAllBytes(filePath));

ms.Position = 0;

LinkedResource lr = new LinkedResource(ms, "image/jpeg");

lr.ContentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Jpeg;

lr.ContentId = "image1";

av.LinkedResources.Add(lr);

m.AlternateViews.Add(av);

SmtpClient client = new SmtpClient("localhost");

client.Send(m);

ms.Close();

 

 

 

 



Answer this question

.NET 2.0 SMTP client HELP: Embedded images show up as red X in the message

  • congminh6

    I tested your code, and it shows up my image, inline, with no problem.
    At least, your code works, that i assure you.

    Also the mail header and data, are the same, except for the quoted-printable boundary, that has another charset, but that should only mess with special characters, and similar things.

    For my testing, I used a simple message: "Inline Test."

    Can it be that your message contains an HTML tag, that invalidates the following HTML ! !
    May it be the SMTP gateway (SMTP Virtual Server)
    May it be your e-mail client

    Hope i could be of any help, good luck.


  • .NET 2.0 SMTP client HELP: Embedded images show up as red X in the message