带有img标签的MainItem.HTMLBody将不显示图像 [英] MainItem.HTMLBody with img tag won't display image
问题描述
在.NET中,我正在使用Microsoft.Office.Interop.Outlook.MailItem来创建电子邮件并将其显示给用户。设置 HTMLBody属性时,指定没有指定'px'的图像在我点击显示时不会显示,但是如果指定了'px',它们就会显示。
In .NET I'm using Microsoft.Office.Interop.Outlook.MailItem to create an email and display it to the user. When setting the HTMLBody property, images that don't have 'px' specified don't show when I hit display, but they do if 'px' is specified.
例如,这将按照您的预期显示图像:
For example, this will show the image just as you would expect:
_outlookMailItem.HTMLBody = "<img src=\"file:///C:/example.png\" width=\"200px\" height=\"100px\" />";
但是下面没有显示图像,只显示了它的预留空间。
But the following does not show the image, just the reserved space for it.
_outlookMailItem.HTMLBody = "<img src=\"file:///C:/example.png\" width=\"200\" height=\"100\" />";
注意唯一的区别是未指定'px'。我不认为这是一个html要求有'px'所以我想知道这是否是一个公认的问题?
Note the only difference is 'px' is not specified. I don't think it's a html requirement to have 'px' so am wondering if this is a recognised issue?
这已成为一个很大的问题,因为html通常来自其他软件所以我希望找到一个不是程序化的解决方案(即使它是短期的)。
This has become quite a big issue since the html is normally from other software so I'm hoping to find a solution (even if it is short-term) that isn't programmatic.
谢谢。
推荐答案
Hello Steve,
Hello Steve,
参见
HTML电子邮件无法在Outlook 2007中正确显示  ;。
无论如何,图像不会显示在收件人方面。您需要嵌入图片并添加"cid:"属性附加文件名。例如,原始草图:
Anyway, images will not be displayed on the recipient side. You need to embed images and add the "cid:" attribute to attached filename. For example, a raw sketch:
Attachment attachment = newMail.Attachments.Add(
@"E:\Pictures\image001.jpg"
, OlAttachmentType.olEmbeddeditem
, null
, "Some image display name");
string imageCid = "image001.jpg@123";
Outlook.PropertyAccessor accessor = attachment.PropertyAccessor;
accessor.SetProperty(
" http://schemas.microsoft.com/mapi/proptag/0x3712001E"
,imageCid);
newMail.HTMLBody = String.Format(
"< body>< img src = \" cid:{0} \">< / body> ;"
,imageCid);
Outlook.PropertyAccessor accessor = attachment.PropertyAccessor; accessor.SetProperty( "http://schemas.microsoft.com/mapi/proptag/0x3712001E" , imageCid); newMail.HTMLBody = String.Format( "<body><img src=\"cid:{0}\"></body>" , imageCid);
不要忘记释放所有底层COM对象即刻。
Don't forget to release all underlying COM objects instantly.
或者只使用全局可用的图像(上传到任何Web服务器)。
Or just use globally available images (uploaded to any web server).
这篇关于带有img标签的MainItem.HTMLBody将不显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!