c# - 将报告作为 html 导出到 Outlook 邮件时的嵌入图像
问题描述
我有这段代码可以将我的报告导出为 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 并且所有图像都内置在控件本身中
解决方案
Outlook 支持将 HTML 图像作为指向 Web 服务器上文件的外部链接或作为对附件的引用 - 在后一种情况下,HTML 正文通过选项卡的src=cid:xyz
属性引用图像附件img
,其中“xyz”是PR_ATTACH_CONTENT_ID
属性的值在附件上。有关详细信息,请参阅如何将资源文件夹中的图像作为附件添加并嵌入到 C#中的 Outlook 邮件正文中。
请注意,Outlook 不支持 base64 编码的嵌入图像 - 这是 Word 限制(Word 在 Outlook 中呈现 HTML 消息)。
推荐阅读
- python - Scrapy 用户代理被阻止或在远程服务器上不起作用
- pine-script - 您将如何修改此 Tradingview Pine 脚本以使最后一个(当前)实时柱像其他柱一样被打印
- python - 使用字符串评估矩阵以获得特征值
- haskell - 为什么与`Ambiguous type..`错误(在ghci中)有如此不同的行为?
- java - (Java) Telegram Bot API EditMessage 响应:[400] 错误请求:无法编辑消息
- android - Parse 无法删除我想要的对象
- html - 我网站的徽标图像在移动设备上模糊不清
- c# - C# 在保留文件结构的同时解压缩目录中的所有嵌套 zip
- reactjs - 如何处理在反应中添加重复项
- java - 使用附加的初始化向量java加密和解密带有流的文件