【问题标题】:Embedded image when export report to outlook mail as html将报告作为 html 导出到 Outlook 邮件时的嵌入图像
【发布时间】:2020-11-07 13:30:28
【问题描述】:

我有这段代码可以将我的报告导出为 html,然后在 Outlook 正文中显示

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;

}

除了图片没有显示在我的 Outlook 正文中之外,一切都很顺利。我希望这样:

但我明白了:

我尝试使用

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

但它似乎只适用于 xrPictureBox,我使用 xrCheckBox 并且所有图像都内置在控件本身中

【问题讨论】:

    标签: c# winforms outlook xtrareport export-to-html


    【解决方案1】:

    Outlook 支持将 HTML 图像作为指向 Web 服务器上文件的外部链接或作为对附件的引用 - 在后一种情况下,HTML 正文通过 img 选项卡的 src=cid:xyz 属性引用图像附件,其中“xyz”是附件上PR_ATTACH_CONTENT_ID 属性的值。详情请见How to add images from resources folder as attachment and embed into outlook mail body in C#

    请注意,Outlook 不支持 base64 编码的嵌入图像 - 这是 Word 的限制(Word 在 Outlook 中呈现 HTML 消息)。

    【讨论】:

    • 真的很抱歉耽搁了,感谢您的帮助。不幸的是,我采取了简单的方法并将所有 xrCheckBox 替换为 xrPictureBox 。以后我会试试你的方法。再次感谢。
    猜你喜欢
    • 2012-03-30
    • 2022-09-25
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 2012-04-22
    • 2020-01-29
    • 1970-01-01
    相关资源
    最近更新 更多