2

If I have a message with an .eml (i.e. message/rfc822) attachment in my mailbox, fetching the message via the REST API returns a Message with a single ItemAttachment. That ItemAttachment encapsulates a Microsoft.OutlookServices.Message representing the attached message. The attached Message object has a null Id, so we can't fetch it directly. But what if we want to fetch the content of one of its attachments?

Message in Inbox
  \--> Attachments
     \--> ItemAttachment
        \--> Item
           \--> Attachments
              \--> FileAttachment    <-- (want the content of this)

That second-level FileAttachment has an @odata.id of:

https://outlook.office.com/api/beta/Users('1985bb55-77bd-4936-868d-a1606dc735ff@3bb3f5a2-37a8-4451-b57b-ef37f0b2a1fa')/('')/Attachments('AAMkAGQ3MzU1BBc2LWFjNTItNDk4Mi1iZTdlLTM3NGM0NzY5NTNmYgBGAAAAAACI4ZQOxnCPTpOe8P6IYO9gBwA_fgVM0BybQ5W_noJvz6hgAAAAAAEMAAA_fgVM0BybQ5W_noJvz6hgAAB2hYE9AAACEgAQAA_BBM8zEqJPrcr4BJ-cOyUSABAAlLV-2suqwEGuRduQ43E9pg==')

But any attempts to fetch that object will fail because of the missing message_id path segment:

{"error":{"code":"RequestBroker-ParseUri","message":"Empty segment encountered in request URL. Please make sure that a valid request URL is specified."}}

How can I fetch the content of that attachment?

Community
  • 1
  • 1
dkarp
  • 14,483
  • 6
  • 58
  • 65

1 Answers1

0

At present, the Outlook REST API doesn't support to get the attachment from an (file/item) attachment of the message. However, based on the link you provide in the post, the MSFT seems already consider to add this feature.

And in your scenario, you want to get the attachment from the message a(.eml format) which is the attachment of message b. The ‘.eml’ attachment actually is an file attachment instead of the item attachment. It means that it would failed event when we try to expand it using the REST below:

GET: https://outlook.office.com/api/v2.0/me/MailFolders/Inbox/messages/{messageID}/attachments/{attachmentId}?$expand=Microsoft.OutlookServices.ItemAttachment/Item

It just return the same result as we get the attachment directly like below: enter image description here

As a workaround, we may save the content bytes of attachment to a temporary file and use other library to retrieve the attachment from ‘.eml’ file.

And the error about ‘RequestBroker-ParseUri’, did you have the message segment in the @odata.id? The correct the @odata.id should be like:

@odata.id=https://outlook.office.com/api/v1.0/Users('username @tenant.onmicrosoft.com')/Messages(AAAAFFtq...JFAAA=')/Attachments(AAAA...InxVMOHvBDM0=')

Update

Message->
         Item attachment(eml)->
                               File attachment

To get the content of the file attachment of an item attachment, we can expand the item attachment using the REST API below:

GET: https://outlook.office.com/api/beta/me/mailfolders/inbox/messages/{messageId}/attachments?$expand=Microsoft.OutlookServices.ItemAttachment/Item

Response: enter image description here

Then we can get the content of the file attachment directly via the ‘ContentBytes’.

Community
  • 1
  • 1
Fei Xue
  • 14,369
  • 1
  • 19
  • 27
  • I would be very happy to get a FileAttachment and parse it myself. These cases are rare enough that that's not a problem. But I'm not getting a FileAttachment. I'm using the beta API and am getting `"@odata.type": "#Microsoft.OutlookServices.ItemAttachment", "@odata.id": "https://outlook.office.com/api/beta/Users('1985bb55-77bd-4936-868d-a1606dc735ff@3913f5a2-37a8-4451-b57b-ef37f0b2a1fa')/Messages('AAMkAGQ3MzU1YTc2L...')/Attachments('AAMkAGQ3MzU...')"` – dkarp Jun 09 '16 at 14:06
  • Thanks for the correction. After using the beta version API, I would able to get the ‘eml’ attachment as item attachment and could reproduce the issue as you described below the id of file attachment return error. In this scenario, we can expand the attachment of the original message to get the content of the file attachment of the item attachment. I update this suggestion above. – Fei Xue Jun 13 '16 at 07:02