1

I have this code that export my report to html then show it on outlook body

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);


using (RepProjectInfoCH report = new RepProjectInfoCH())
{
    report.DataSource = await ProjInfo.RepProjectInfoCH(idProject).ConfigureAwait(true);

    string str;
    MemoryStream ms = new MemoryStream();
    try
    {

        report.ExportToHtml(ms);
        ms.Seek(0, SeekOrigin.Begin);
        using (StreamReader sr = new StreamReader(ms))
        {
            str = sr.ReadToEnd();
        }
    }
    finally
    {
        ms.Close();
    }

    oMsg.To = "Test@Test.com";
    oMsg.Subject = "Test" ;
    oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
    oMsg.Display(false); //In order to display it in modal inspector change the argument to true
    oMsg.HTMLBody = str + oMsg.HTMLBody; //Here comes your body;

}

All things go well except for images does not show in my outlook body. I expect this:

enter image description here

but I get this:

enter image description here

I tried to use

HtmlExportOptions htmlOptions = report.ExportOptions.Html;
htmlOptions.EmbedImagesInHTML = true;

but it seems to work with xrPictureBox only and I use xrCheckBox and all image are built-in within controls themselves

Dale K
  • 25,246
  • 15
  • 42
  • 71
M.Bouabdallah
  • 530
  • 10
  • 29

1 Answers1

2

Outlook supports HTML images either as external links to files on a web server or as references to an attachment - in the latter case, the HTML body references the image attachment through the src=cid:xyz attribute of the img tab, where "xyz" is the value of the PR_ATTACH_CONTENT_ID property on the attachment. See How to add images from resources folder as attachment and embed into outlook mail body in C# for more details.

Note that Outlook does not support base64-encoded embedded images - this is a Word limitation (Word renders HTML messages in Outlook).

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I am really sorry for the delay, and thank you for your help. Unfortunately, I've taken the easy way and replaced all xrCheckBox with xrPictureBox . I'll try your way in the future. big thanks again. – M.Bouabdallah Aug 22 '20 at 19:14