1

I am using the the following Graph API URL to retrieve the filename(s) attached to an email:

https://graph.microsoft.com/v1.0/me/messages/*/attachments

however, it is no longer returning the attached filename(s) for '.msg' files. The file extension is missing. Please see below example returns:

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('')/messages('')/attachments",
"value": [
{
"@odata.type": "#microsoft.graph.itemAttachment",
"id": "*",
"lastModifiedDateTime": "2021-08-13T11:21:29Z",
"name": "Original Email",
"contentType": null,
"size": 45795,
"isInline": false
}
]
}

Where as it is for other file types:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('')/messages('')/attachments",
"value": [
{
"@odata.type": "#microsoft.graph.fileAttachment",
"@odata.mediaContentType": "application/octet-stream",
"id": "",
"lastModifiedDateTime": "2021-08-13T11:14:07Z",
"name": "Original Email.mht",
"contentType": "application/octet-stream",
"size": 54693,
"isInline": false,
"contentId": null,
"contentLocation": null,
"contentBytes": ""
}
]
}

NB: sensitive info has been redacted (*).

I can see that the @odata.type is returned differently:

@odata.type": "#microsoft.graph.itemAttachment
@odata.type": "#microsoft.graph.fileAttachment

I'm not sure why this is, the email is attached in the same way.

In both of the above cases, using Outlook, I sent myself an email, saved it to my local filesystem, created another email, attached the previously saved file and sent myself the new email with the saved email attached. Then made the request using the stated URL (and many other variations).

I have looked all over and no request URL that I have used returns the file extension for this type.

Is there a way to return the filename for '.msg' files?

2 Answers2

1

Edit: this is how (java) I'm getting the filename for Attachment(s) (except ReferenceAttachment as I'm not handling them)

    public String getCurrentAttachmentName()
    {
        String fileName = null;
        if (currentAttachment instanceof FileAttachment)
        {
            fileName = currentAttachment.name;
        } else if (currentAttachment instanceof ItemAttachment)
        {
            if (null != currentAttachment.contentType)
            {
                fileName = currentAttachment.name;
            } else
            {// outlook email or contact etc., add extension
                ItemAttachment itemAttachment = (ItemAttachment) currentAttachment;
                if (itemAttachment.item instanceof Contact)
                {
                    fileName = currentAttachment.name + ".vcf";
                } else if (itemAttachment.item instanceof Message)
                {
                    fileName = currentAttachment.name + ".eml";
                } else if (itemAttachment.item instanceof Event)
                {
                    fileName = currentAttachment.name + ".ics";
                } else
                {
                    fileName = currentAttachment.name + ".bin"; // should be unreachable but just in case.
                }

            }
        }
        // looping does not allow ReferenceAttachment so we don't need to handle that type
        return fileName;

    }

0

MS graph differentiates the attachments at resource level ie fileAttachment resource type and itemAttachment resource type

Even though attached the same way, the contact, event, or message attachments belong to itemAttachment resource type and have different props from the file attachments.

Danstan
  • 1,501
  • 1
  • 13
  • 20