Embedded Images in HTML Email Not Displaying on Mobile Phones

I have an application that sends an HTML letter with embedded images. Email is ideal for many different desktop / web clients. When an email is viewed on a mobile phone that supports HTML email (tested on iPhone, WinMo 6.1), the images appear as red “X”. All other HTML is displayed correctly. To be clear, the problem ONLY occurs on mobile clients, not desktop clients.

The code for embedding images works fine, and I do not believe that there are any problems with it, but just in case, I included some simple code examples:

MailMessage mail = new MailMessage();
            mail.To.Add("123@myemail.com");
            mail.From = new MailAddress("456@ myemail.com");
            mail.Subject = "Image sample - fails in mobile clients";
            string Body = "Sample email text<img src=\"cid:imageId\" />";

            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
            LinkedResource lr = new LinkedResource("myImage.jpg");
            lr.ContentId = "imageId";
            htmlView.LinkedResources.Add(lr);

            mail.AlternateViews.Add(htmlView);
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Send(mail);

- , ? , ?

: Outlook 2007 ( ) , . HTML- , , .

Outlook , - ( ) . ?

+5
4

- : ContentType LinkedResource .

MSDN:

ContentType , . ContentType - Attachment .

Outlook , , .

+3

, . , , , , . , . . . , .

0

:

string attachmentPath = Environment.CurrentDirectory + @"\test.png";
Attachment inline = new Attachment(attachmentPath);
inline.ContentDisposition.Inline = true;
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
inline.ContentId = contentID;
inline.ContentType.MediaType = "image/png";
inline.ContentType.Name = Path.GetFileName(attachmentPath);

message.Attachments.Add(inline);

I just tested it and it worked like a charm. You, of course, want to determine your file type. Here is a list of media types:

http://www.fileformat.info/info/mimetype/image/index.htm

0
source

All Articles