Request for retrieving email message and expanding attachments doesn't retrieve referenceattachments - microsoft-graph-api

retrieving email message expanding attachments doesn't retrieve referenceattachments (that we upload using upload & share from onedrive)
If an email contains only reference attachments the list would return empty
GET /users/{id | userPrincipalName}/messages/{id}/attachments
I tried following request
GET /users/{id | userPrincipalName}/messages/{id}?$expand=attachments
The above request gets all the attachments however reference attachments are not included in the result.

Try using below URL
GET https://graph.microsoft.com/v1.0/me/messages/{id}/?$expand=microsoft.graph.itemattachment/item
See the docs for more info - https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http#example-4-expand-and-get-the-properties-of-an-item-attached-to-a-message-including-any-attachment-to-the-item

Related

How can I determine the original message of a reply?

Using Microsoft Graph, how can I determine which message an outgoing message is a reply to?
The internetMessageHeaders property is not available for items in the Sent Items folder of mailboxes (using the Graph API, at least -- they are available using EWS or IMAP). If it were, I'd look for the in-reply-to header. In the absence of this, is there something in the standard Graph message properties that will tell me this?
You can check the "Subject" or "bodyPreview" to check if the content contains "RE:", if the answer is yes, the message is reply to.
You can group the message by conversationId and then order by lastModifiedDateTime. This way can check if the message is the original one, if it is not ,it will be reply-to/follow-up one.
Get the message list first(/me/messages or /users/{id | userPrincipalName}/messages and so on), and then foreach the message id to call reply api(/users/{id | userPrincipalName}/messages/{id}/reply and so on). The result in the reply is a reply to.
To Test this, you can use the Graph Explorer first and then paste the JSON to a JSON viewer tool. For further use, you need to use net/java and so on to handle.
API reference: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/message
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/message_reply

How to send nested attachments?

Stuck here writing JS code to send out an email via REST within a custom Outlook add-in.
Scenario is following
report
\
\---- another message (item attachment)
\
\------- attachment (file attachment)
In words, I am sending a new report message which includes another message as an Item Attachment (that works fine).
But now, the problem is that, when sending with another message that has attachments, then this fails. Opening the report which has the other message attached doesn't show the attachments.
Query is POST https://outlook.office365.com/api/v2.0/me/sendmail
Returns 202 Accepted
Body is quite long and on this Gist
https://gist.github.com/binarykitchen/2b95331c5c85e7cb4ca6f6917dc67a67
You can see Message has Attachments which has an Item Attachment (attaching another message) which has one file attachment called "bat_kitten.jpeg"
How come this sent message doesn't have this file attachment but server still responds with accepted 202?
Maybe some parameters are wrong? Not sure what to set for ContentId and ContentLocation for that file attachment?
Or are nested attachments not supported yet?
Any clues would be very much appreciated.

MS Graph API response not returning all the data items it supposed to

My intention is to build a Machine Learning program that will give a recommendation for archiving email item by reading all previous email history.
For that, I am trying to read all the email item from:
https://graph.microsoft.com/beta/me/messages
First I am getting the total number of email items in my account using /messages?$count=true which returns 1881 as the result.
Then I am trying to get all the 1881 item using:
https://graph.microsoft.com/beta/me/messages?$top=1881
But the problem is that returns 976 email items. Where are the rest of the email item? How I can find them?
Are you getting a #odata:nextLink property in your response?
If that's the case, you might need to send another request with a skiptoken parameter. It should contain a value from the #odata:nextLink response property.
On the "paging" documentation page - https://developer.microsoft.com/en-us/graph/docs/concepts/paging - it is specified that different APIs have different max page size. It's possible that the endpoint for fetching emails does not support a page size of 1881. In that case, you might need to access a second page of the results.
Another suggestion is to replace beta endpoint with the V1 API call because me/messages is available there also - https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_list_messages

How to retrieve attachments of an ItemAttachment from Office 365 REST API?

Assume I have an event (that has attachments) attached to my email, then I will use the api call provided here and get the event details, but I see that "Id" property is missing in the response. The same happens for messages as attachments. My problem is if I do not have the eventId or messageId, then I am not able to get their attachments.
Please see the below picture which shows the response from the provided api call here.
As mentioned here, we can use the following api call:
GET https://outlook.office.com/api/beta/me/messages/[message-id]?$expand=Attachments($expand=Microsoft.OutlookServices.ItemAttachment/Item($expand=Microsoft.OutlookServices.Event/Attachments))

MailCore2 - Fetch message content without downloading images or attachments?

I want to provide a preview of a user's messages, but I don't wish to download attachments just in order to do that.
The information I need is:
Subject
Date
Sender information (display name if available, email address)
Plain-text message
By calling the method fetchMessagesByNumberOperationWithFolder: with request kind MCOIMAPMessagesRequestKindHeaders, I get the date and subject, but it's very slow to return if any of the messages have attachments. By calling it with request kind MCOIMAPMessagesRequestKindUid, it returns very quickly, with just the Uid (and the current date, as a placeholder). From there, I still need to get the subject, the date and the sender.
Now I'm still trying to get this information, while avoiding downloading message attachments.
Calling fetchParsedMessageOperationWithFolder: or fetchMessageOperationWithFolder: both download the message with attachments, and are thus very slow to return.
Because fetchMessageOperationWithFolder: completes with a NSData object, checking the size of the given object reveals it to be the size of a regular message, plus its' attachment.
What can I do to get the information I need, without downloading any attachments?
EDIT: Calling requiredPartsForRendering could give me the content of the email, but in order to retrieve the Date and sender information, I'd still have to have a request kind of MCOIMAPMessagesRequestKindHeaders, which would download the attachment.
So to clarify:
I want to get the following information from an IMAP email, without downloading the email attachments:
Subject
Date
Sender information (display name if available, email address)
Plain-text message
The following methods should be helpful to you:
-[MCOAbstractMessage requiredPartsForRendering] will return the message parts that you needs to fetch to be able to show the text content of the message.
-[MCOIMAPSession fetchMessageAttachmentOperationWithFolder:uid:partID:encoding:] will help you fetch each of those parts.
-[MCOIMAPMessage htmlRenderingWithFolder:delegate:] will return the rendered content as HTML (or nil if you don't provide all the content of the parts through the delegate.
-[NSString mco_flattenHTML] is also useful if you'd like to convert the HTML to a unformatted string.

Resources