简体   繁体   English

如果附件本身是邮件,如何在 Outlook 中以编程方式访问附件数据

[英]How to access attachment data programmatically in outlook if attachment is itself a mail

I am programmatically trying to get the attachment data in C# in following way :--我正在以编程方式尝试通过以下方式在 C# 中获取附件数据:--

Microsoft.Office.Interop.Outlook.Attachment attachment = objMail.Attachments[attachmentIndex];

if (attachment.DisplayName.Equals("Test"))

{ 

   const string PR_ATTACH_DATA = "http://schemas.microsoft.com/mapi/proptag/0x37010102";

    byte[] attachmentData = attachment.PropertyAccessor.GetProperty(PR_ATTACH_DATA);

}

Now my code is working fine if attachment is text file or image file.如果附件是文本文件或图像文件,现在我的代码工作正常。 But if attachment is itself a mail, it throws the exception that property is unknown or can not be found.但如果附件本身是邮件,则会抛出属性未知或无法找到的异常。

Please suggest in which cases / type of attachments, this property " http://schemas.microsoft.com/mapi/proptag/0x37010102 " will not work and in those cases, what would be alternative property / method to get the attachment data in byte array ?请建议在哪些情况下/附件类型,此属性“ http://schemas.microsoft.com/mapi/proptag/0x37010102 ”将不起作用,在这些情况下,获取附件数据的替代属性/方法是什么字节数组?

Thanks谢谢

PR_ATTACH_DATA_BIN is only present for the regular by-value attachments ( PR_ATTACH_METHOD == ATTACH_BY_VALUE ). PR_ATTACH_DATA_BIN仅适用于常规的按值附件( PR_ATTACH_METHOD == ATTACH_BY_VALUE )。 Embedded message or OLE attachments do not expose that property - they use PR_ATTACH_DATA_OBJ which must be opened using IAttach::OpenProperty(IID_IStorage, ...) - take a look at the existing messages using OutlookSpy (select the message, click IMessage button, go to GetAttachmentTable tab, double click on the attachment).嵌入的消息或 OLE 附件不公开该属性 - 它们使用PR_ATTACH_DATA_OBJ必须使用IAttach::OpenProperty(IID_IStorage, ...)打开 - 使用OutlookSpy查看现有消息(选择消息,单击 IMessage 按钮,转到到 GetAttachmentTable 选项卡,双击附件)。

Also keep in mind that PropertyAccessor.GetProperty would only be able to retrieve that property for small attachments.还要记住, PropertyAccessor.GetProperty只能为小附件检索该属性。 For large attachments, PR_ATTACH_DATA_BIN must be opened as IStream using IAttach::OpenProperty(IID_IStorage, ...) - PropertyAccessor.GetProperty does not do that.对于大附件, PR_ATTACH_DATA_BIN必须为已打开IStream使用IAttach::OpenProperty(IID_IStorage, ...) - PropertyAccessor.GetProperty没有做到这一点。 You will need to use Extended MAPI (C++ or Delphi) or Redemption (which exposes RDOAttachment . AsArray / AsText / AsStream properties.您将需要使用扩展 MAPI(C++ 或 Delphi)或Redemption (暴露RDOAttachment . AsArray / AsText / AsStream属性。

Microsoft Graph Rest API is an single end point and wrapper for most Microsoft Data including events, most office products including outlook. Microsoft Graph Rest API 是大多数 Microsoft 数据(包括事件)、大多数办公产品(包括 Outlook)的单一端点和包装器。 Best of all any language can make a request to the endpoint and retrieve the information.最重要的是,任何语言都可以向端点发出请求并检索信息。 See the complete Docs HERE to get started.请在此处查看完整的文档以开始使用。

See below code for a simple Get request for outlook attachments.有关 Outlook 附件的简单 Get 请求,请参阅下面的代码。 Note there are other more complex implementations.请注意,还有其他更复杂的实现。 Docs: https://docs.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http Scroll through the link and you can find C#, Java, and JavaScript examples on how to implement this.文档: https : //docs.microsoft.com/en-us/graph/api/attachment-get? view = graph-rest-1.0 & tabs =http滚动链接,您可以在以下位置找到 C#、Java 和 JavaScript 示例如何实现这一点。

GET /me/messages/{id}/attachments/{id}
GET /users/{id | userPrincipalName}/messages/{id}/attachments/{id}

GET /me/messages/{id}/attachments/{id}/$value
GET /users/{id | userPrincipalName}/messages/{id}/attachments/{id}/$value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM