I am having trouble getting my images to display as part of the HTML body of a mailmessage that also contains a calendar attachment (iCal).
What I am attempting to do is: Send a calendar invite which is recognized by outlook and also contains an HTML body (also displayed in Outlook 2013). That HTML should display a header and footer image inline.
My code works when viewed in gmail, but it will not display the images in Outlook - instead it shows the "header.jpg" and "footer.jpg" in the location of the body where I want the images actually displayed.
I've tried a lot of modifications to this code base - either the calendar invite portion is ignored (and then the images work), or the calendar invite portion works and the images are not displayed but replaced by the "header.jpg" and "screen.jpg" files that open fine when double-clicked. Can I get around this and display the images inline in Outlook?
Here is the code I am working with (snipped irrelevant stuff):
var header = new LinkedResource("header.jpg", MediaTypeNames.Image.Jpeg);
header.ContentId = Guid.NewGuid().ToString();
header.TransferEncoding = TransferEncoding.Base64;
header.ContentType = new ContentType("image/jpg");
header.ContentType.Name = "header.jpg";
header.ContentLink = new Uri(string.Format("cid:{0}", header.ContentId));
var screen = new LinkedResource("screen.jpg", MediaTypeNames.Image.Jpeg);
screen.ContentId = Guid.NewGuid().ToString();
screen.TransferEncoding = TransferEncoding.Base64;
screen.ContentType = new ContentType("image/jpg");
screen.ContentType.Name = "screen.jpg";
screen.ContentLink = new Uri(string.Format("cid:{0}", screen.ContentId));
var sb = new System.Text.StringBuilder();
var dtStart = appointmentStart;
var dtEnd = appointmentEnd;
var htmlcontent = string.Format("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" +
"<HTML><HEAD><META http-equiv=Content-Type content=\"multipart/alternative; charset=iso-8859-1\"></HEAD>" +
"<BODY>" +
"<img src=\"cid:" + header.ContentId + "\"/>" +
"<div><strong>The bold works fine, but the header and footer don't work! /strong></div>" +
"<br />" +
"<div><img src=\"cid:" + screen.ContentId + "\"/></div>" +
"</BODY></HTML>"
);
var plaincontent = String.Format("snip snip");
var av1 = AlternateView.CreateAlternateViewFromString(htmlcontent, new ContentType("text/html"););
av1.LinkedResources.Add(header);
av1.LinkedResources.Add(screen);
sb.AppendLine("BEGIN:VCALENDAR");
sb.AppendLine("VERSION:2.0");
sb.AppendLine("METHOD:REQUEST");
sb.AppendLine("BEGIN:VEVENT");
sb.AppendLine(request.ContactEmail);
sb.AppendLine("CLASS:PUBLIC");
sb.AppendLine(string.Format("CREATED:{0:yyyyMMddTHHmmss}", DateTime.Now));
sb.AppendLine("DESCRIPTION:" + plaincontent);
sb.AppendLine("X-ALT-DESC;FMTTYPE=text/html:" + htmlcontent);
sb.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", dtStart.ToUniversalTime()));
sb.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", dtEnd.ToUniversalTime()));
sb.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.Now.ToUniversalTime()));
sb.AppendLine("ORGANIZER;CN=\"TheOrganizer\":mailto:" + "TheOrganizer@foobar.com");
sb.AppendLine("SEQUENCE:0");
sb.AppendLine("UID:" + request.EmailNotificationUniqueId);
sb.AppendLine("LOCATION:" + request.Location + " : " + request.LocationInformation);
sb.AppendLine("SUMMARY;LANGUAGE=en-us:" + "removed");
sb.AppendLine("BEGIN:VALARM");
sb.AppendLine("TRIGGER:-PT1440M");
sb.AppendLine("ACTION:DISPLAY");
sb.AppendLine("DESCRIPTION:Reminder");
sb.AppendLine("END:VALARM");
sb.AppendLine("END:VEVENT");
sb.AppendLine("END:VCALENDAR");
var icsView = AlternateView.CreateAlternateViewFromString(sb.ToString(), new ContentType("text/calendar"));
var message = new MailMessage();
message.AlternateViews.Add(body);
message.AlternateViews.Add(icsView);
return message;
Is there something fundamentally wrong? This seems like it should be pretty simple and straightforward. I've done this plenty of times with normal email messages, but it seems outlook doesn't like the .ics attachment with images in the body of the HTML alternative view. The HTML body works fine (the shows bolded) but the darn embedded images just won't show.
I've tried manually encoding the images using base64 and that didn't help at all. I've tried with and without the HTML header tags in the htmlContent var, and that didn't make any difference either.
This shouldn't be this difficult - what am I missing?
EDIT: Here is the message source in google. This works fine in the google browser window (displays properly.) Unfortunately in Outlook the message does not work... Maybe the exchange server is supressing the images for internall messages? Is that even a thing?
Delivered-To: snip@gmail.com
Received: by 10.182.167.74 with SMTP id zm10csp2847908obb;
Fri, 7 Oct 2016 15:42:14 -0700 (PDT)
X-Received: by 10.37.171.105 with SMTP id u96mr17483671ybi.63.1475880134797;
Fri, 07 Oct 2016 15:42:14 -0700 (PDT)
Return-Path: <snip@snip.com>
Received: from msg12.snip.com (msg12.snip.com. [192.195.66.28])
by mx.google.com with ESMTPS id q11si2985157ywc.340.2016.10.07.15.42.14
for <snip@gmail.com>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Fri, 07 Oct 2016 15:42:14 -0700 (PDT)
Received-SPF: pass (google.com: domain of snip@snip.com designates 192.195.66.28 as permitted sender) client-ip=192.195.66.28;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of snip@snip.com designates 192.195.66.28 as permitted sender) smtp.mailfrom=snip@snip.com
Received: from int11.snip.pvt (int11.snip.pvt [153.6.62.222]) by msg12.snip.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.2.2) with ESMTP id u97MgC5a022486 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for <snip@gmail.com>; Fri, 7 Oct 2016 22:42:12 GMT
Received: from snip.com (snip.com [snip]) by int11.snip.pvt (Sentrion-MTA-4.3.1/Sentrion-MTA-4.2.2) with ESMTP id u97MgBAv016400 for <snip@gmail.com>; Fri, 7 Oct 2016 22:42:12 GMT
Received: from snip.com with Microsoft SMTPSVC(7.5.7601.17514);
Fri, 7 Oct 2016 18:42:12 -0400
MIME-Version: 1.0
From: snip <snip@snip.com>
To: snip@gmail.com
Date: 7 Oct 2016 18:42:12 -0400
Content-Type: multipart/alternative; boundary=--boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042
Message-ID: <5U9T3T00000050@snip.com>
X-OriginalArrivalTime: 07 Oct 2016 22:42:12.0895 (UTC) FILETIME=[0BC44AF0:01D220EC]
X-Flow-Control: Sendmail Flow Controller v2.2.5 int11.snip.pvt u97MgBAv016400
X-Flow-Control-Info: class=Default rcpts=1 size=37636
----boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042
Content-Type: multipart/related; boundary=--boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac; type="text/html"
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<img src=3D"cid:443ba735-6376-45a1-a5af-6c679321baa2"/><div><strong>The bol=
d works fine, but the header and footer don't work!</strong></div><br /><di=
v><img src=3D"cid:145c43b0-da9e-40c4-b149-3a149fbc4503"/></div>
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <443ba735-6376-45a1-a5af-6c679321baa2>
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <145c43b0-da9e-40c4-b149-3a149fbc4503>
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac--
----boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042
Content-Type: text/calendar
Content-Transfer-Encoding: base64
QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KTUVUSE9EOlJFUVVFU1QNCkJFR0lOOlZFVkVO
VA0KSmRyYWhsQGdtYWlsLmNvbQ0KQ0xBU1M6UFVCTElDDQpDUkVBVEVEOjIwMTYxMDA3VDE4NDIx
MQ0KREVTQ1JJUFRJT046DQpYLUFMVC1ERVNDO0ZNVFRZUEU9dGV4dC9odG1sOjxpbWcgc3JjPSJj
aWQ6NDQzYmE3MzUtNjM3Ni00NWExLWE1YWYtNmM2NzkzMjFiYWEyIi8+PGRpdj48c3Ryb25nPlRo
ZSBib2xkIHdvcmtzIGZpbmUsIGJ1dCB0aGUgaGVhZGVyIGFuZCBmb290ZXI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