在VSTO C#中获取RTF邮件的附件内容

发布于 2025-02-02 20:16:14 字数 78 浏览 2 评论 0 原文

我们正在尝试获取RTF邮件中附件的内容,但我尝试使用不同的术语搜索,但没有找到任何可靠的解决方案。有人可以帮助我以HTML格式获得附件的来源。

we are trying to get the content of the attachment's of the in the rtf mail but I have tried to search using different terms but have not found any reliable solution . can someone please help me to get the source of the attachment's as we get them in the html format.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与之呼应 2025-02-09 20:16:14

Outlook对象模型不提供任何获取附件内容的属性或方法。要连接文件,您需要将其保存到磁盘上,然后从那里读取内容。

另外,您可以考虑使用Outlook基于扩展MAPI的低级API。它允许获取所附文件的二进制数据。尝试使用 attactment.propertyaccessor.getProperty 方法传递“ http://schemas.microsoft.com/mapi/mapi/mapi/proptag/0x37010102”( pr_attach_data_data_bin )。

set msg = Application.ActiveExplorer.Selection(1)
set attach = msg.Attachments(1)
set ps = attach.PropertyAccessor
v = ps.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x37010102")
debug.print ps.BinaryToString(v)

The Outlook object model doesn't provide any property or method for getting the attachment content. To get the file attached you need to save it to the disk and then read the content from the there.

Also you may consider using a low-level API on which Outlook is based on - Extended MAPI. It allows getting the binary data of the attached file. Try using the Attachment.PropertyAccessor.GetProperty method while passing in the value "http://schemas.microsoft.com/mapi/proptag/0x37010102" (PR_ATTACH_DATA_BIN).

set msg = Application.ActiveExplorer.Selection(1)
set attach = msg.Attachments(1)
set ps = attach.PropertyAccessor
v = ps.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x37010102")
debug.print ps.BinaryToString(v)
忆离笙 2025-02-09 20:16:14

在低级别(C ++或Delphi中的扩展MAPI)上,您需要打开 pr_attach_data_obj 属性为 istorage 并从那里提取数据(这取决于实际类型附件)。您可以在 iMessage OutlookSpy色带上的按钮,转到 getAttachmentTable TAB,双击附件上的附件,选择 pr_attach_data_obj 属性,右键单击,选择 imapiprop :: OpenProperty ,然后 istorage 。原始数据以及代表附件的图像将存在(因此Outlook在渲染消息时不必启动主机应用程序)。

如果使用 rexemption 是一个选项(我也是它的作者,可以从任何语言中使用,包括任何语言c#and vba),其版本的 rdoattachment 。方法处理大多数流行格式的OLE附件(Word,Excel,Bitmap,Power Point,Adobe PDF等) - 创建一个 rdosession 对象(使用 crealeoleobject redemptivemtionloader )并使用 rdosession.getRdoObject fromoutlookObject 方法(通过 mailItem 或或附件附件对象) rdomail rdoattachment 对象。

On the low level (Extended MAPI in C++ or Delphi), you need to open the PR_ATTACH_DATA_OBJ property as IStorage and extract the data from there (it depends on the actual type of the attachment). You can see the data in the streams in OutlookSpy (I am its author) - select the message, click IMessage button on the OutlookSpy ribbon, go to the GetAttachmentTable tab, double click on the attachment to open it, select the PR_ATTACH_DATA_OBJ property, right click, select IMAPIProp::OpenProperty, then IStorage. Raw data will be there as well as an image representing the attachment (so that Outlook won't have to start the host app when rendering the message).

If using Redemption is an option (I am also its author, it can be used from any language including C# and VBA), its version of RDOAttachment.SaveAsFile method handles OLE attachments for most popular formats (Word, Excel, bitmap, Power Point, Adobe PDF, etc.) - create an instance of the RDOSession object (using either CrealeOleObject or RedemptionLoader) and use RDOSession.GetRDOObjectFromOutlookObject method (pass either MailItem or Attachment object) to get back RDOMail or RDOAttachment object respectively.

如何视而不见 2025-02-09 20:16:14

我发现了一种解决方案,可以直接从RTF邮件中获取图像内容,直接击中低级API或其他任何内容。
该解决方案不是直接的,

  1. 使用Odoc.saveas2(filepath,wdsaveformat.wdformatfilteredhtml)将邮件保存到磁盘上。
  2. 保存邮件后,您将获得保存.htm文档的文件夹
    现在阅读.htm doc
  3. 使用图像点数获取.htm doc的所有图像节点,
  4. 您可以使用图像的src nods
  5. 使用图像的src node获得src属性,直接您可以直接从磁盘本身获取图像那张图像

i have been found a solution for getting the images content from the rtf mail directly whiteout hitting the low level api or anything.
the solution is not a straight forward one

  1. save the mail to the disk using oDoc.SaveAs2(filepath, WdSaveFormat.wdFormatFilteredHTML);
  2. after saving the mail you will get the folder which you save a .htm doc
    now read the .htm doc
  3. get the all the image nodes of the .htm doc
  4. using the image nods you can get src attribute of the image node
  5. using the src value of the image you get the image directly from the disk itself and you can use that image
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文