NakedBrunch
NakedBrunch

Reputation: 49413

Embedded images in HTML email not displaying on mobile phones

I have an application that sends an HTML formatted email with embedded images. The email looks perfect on many different desktop/web clients. When the email is viewed on a mobile phone that supports HTML email (tested on iPhone, WinMo 6.1) the images are displayed as red 'X's. All other HTML is being displayed correctly. To be clear, the problem is ONLY occurring on mobile clients and not on desktop clients.

The code to embed images is working perfectly and I don't believe there is any problem with it but I've included some quick sample code below just in case:

MailMessage mail = new MailMessage();
            mail.To.Add("[email protected]");
            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);

Does anyone know why embedded images are not displayed on mobile clients? Better yet, how can I get the images to display correctly?

Edit: If Outlook 2007 (and above) sends an email with images then the images are displayed correctly in a mobile client and desktop client. If an HTML formatted email is sent with embedded images then the images are not displayed correctly in the mobile client but are correctly displayed in a desktop client.

How is Outlook able to send emails with images confidently displayed but if sent through a web app (using embedded images) the mobile client blocks the images. What is the difference between the two?

Upvotes: 5

Views: 10558

Answers (4)

Sonic Soul
Sonic Soul

Reputation: 24919

good answer here:

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'll want to determine your file type of course. here is a list of media types:

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

Upvotes: 0

NakedBrunch
NakedBrunch

Reputation: 49413

I finally found an answer to this problem: The optional ContentType of the LinkedResource was not set. Desktop clients can figure out

From MSDN:

The information in the ContentType class is used to describe the data contained in an e-mail message in such a way that software that displays e-mail can present the content in an appropriate manner. ContentType is used with the Attachment class to specify the type of content in the attachment.

Outlook was able to understand how the attached image was to be displayed but the mobile clients required more information.

Upvotes: 3

rob - not a robber
rob - not a robber

Reputation: 505

This is as other users said, a preferences issue and a known bug.

Alison, are you positive that the image binaries made their way to the phone? As other users stated, the preferences issue might be a default to cut down on the inadvertent download of bulky images to mobile clients with limited data plans.

As for the known issue, please see

http://www.google.com/support/forum/p/Google+Mobile/thread?tid=6470e77d94f0315c&hl=en

Thanks and good luck...

EDIT: Whoa... this is an oldie question ;)

Upvotes: 2

BBlake
BBlake

Reputation: 2398

Most often the cause is the settings on the smart phone being set to prevent the downloading of email images by default. On most phones, the default behavior is that they have to download the images manually, usually by a button or setting in the email client, if they want to see the images attached to that particular email. It's the same setting I use in my desktop and laptop Outlook settings as well. For most email clients, it's a spam protection thing. For the phones, it's also to save bandwidth from unnecessary usage. You should never count on the clients always seeing the images by default.

Upvotes: 0

Related Questions