Create new mail message with Microsoft Graph API - microsoft-graph-api

When using the MS Graph API to POST a Mail message, the message is created in DRAFT mode. Is there any way to create a new regular mail message which is not in DRAFT?
In addition, is there any option to POST a new message using MIME format in the body?

When you create the Message you need to set the MessageFlags extended property to make it appear as if it was a Sent Message. You generally also want to set the ClientSubmitTime https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagclientsubmittime-canonical-property and the delivery time https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagmessagedeliverytime-canonical-property which affect how the messages will sort in Outlook. For MIME its export only in Beta at the moment https://developer.microsoft.com/en-us/graph/blogs/mime-format-support-for-microsoft-graph-apis-preview/
{
"Subject": "test1234",
"Sender": {
"EmailAddress": {
"Name": "blah",
"Address": "blah#blah.com"
}
},
"Body": {
"ContentType": "HTML",
"Content": "123Body"
},
"SingleValueExtendedProperties": [
{
"PropertyId": "Integer 0x0E07",
"Value": "1"
},
{
"PropertyId": "SystemTime 0x0039",
"Value": "2019-06-12T10:10:47.2048+10:00"
},
{
"PropertyId": "SystemTime 0x0E06",
"Value": "2019-06-12T10:10:47.2048+10:00"
}
]
}

Related

How to find parent_message_id of reply message in graph api

I mean that Incoming reply mail is which mail reply,
To find this I want parent_message_id by using this I'm easily find parent_mail.
below code is respone of reply mail.
I want to find It's parent mail means below mail is which mail reply
To find parent mail I want parent_mail_id How can I find this ?
{
"#odata.etag": "W/\"CQAAABYAAABexZ50mSS0TKajvW/Uc3jZAAAhk64J\"",
"id": "AQMkADAwATM3ZmYAZS01OWRhLTM5MjgtMDACLTAw....",
"createdDateTime": "2023-02-02T08:39:59Z",
"lastModifiedDateTime": "2023-02-02T08:40:01Z",
"changeKey": "CQAAABYAAABexZ50mSS0TKajvW/Uc3jZAAAhk64J",
"categories": [],
"receivedDateTime": "2023-02-02T08:40:00Z",
"sentDateTime": "2023-02-02T08:39:46Z",
"hasAttachments": false,
"internetMessageId": "<CAJjLavQHv0SDMHxiKpRUCE=NU9X4AnL2QfPKjLJMbPeudvNP-A#mail.gmail.com>",
"subject": "Re: Meet for lunch 12:40?",
"bodyPreview": "12:40 reply mail\r\n\r\nOn Thu, 2 Feb 2023 at 13:06, ** <****#outlook.com> wrote:\r\nThe new cafeteria is open.",
"importance": "normal",
"parentFolderId": "AQMkADAwATM3ZmYAZS01OWRhLTM5MjgtMDACLTAwCgAuAAADNqdil3J7jU_HbfQfdBJYbQEAXsWedJkktEymo71v1HN42QAAAgEMAAAA",
"conversationId": "AQQkADAwATM3ZmYAZS01OWRhLTM5MjgtMDACLTAwCgAQAAo6snnrhhJOv0qLJ4Io1Fo=",
"conversationIndex": "AQHZNtkeCjqyeeuGEk6/SosngijUWq67VhwA",
"isDeliveryReceiptRequested": null,
"isReadReceiptRequested": false,
"isRead": false,
"isDraft": false,
"webLink": "https://outlook.live.com/owa/?ItemID=AQMkADAwATM3ZmYAZS01OWRhLTM5MjgtMDACLTAwCgBGAAADNqdil3J7jU%2BHbfQfdBJYbQcAXsWedJkktEymo71v1HN42QAAAgEMAAAAXsWedJkktEymo71v1HN42QAAACGV0fkAAAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification": "focused",
"body": {
"contentType": "html",
"content": "<html><head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><div dir=\"ltr\">12:40 reply mail </div><br><div class=\"gmail_quote\"><div dir=\"ltr\" class=\"gmail_attr\">On Thu, 2 Feb 2023 at 13:06, ** <***#outlook.com> wrote:<br></div><blockquote class=\"gmail_quote\" style=\"margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex\">The new cafeteria is open.</blockquote></div></body></html>"
},
"sender": {
"emailAddress": {
"name": "****",
"address": "***#gmail.com"
}
},
"from": {
"emailAddress": {
"name": "****",
"address": "****"
}
},
"toRecipients": [
{
"emailAddress": {
"name": "***",
"address": "****#outlook.com"
}
}
],
"ccRecipients": [],
"bccRecipients": [],
"replyTo": [],
"flag": {
"flagStatus": "notFlagged"
}
},
I've send mail by using /sendMail graph api and for this sent mail I've reply mail by using other platform(ex:gmail) ,So how can I know incoming message parent message I mean which message reply is it
You need to take the conversationId from your message and filter messages by conversationId
GET https://graph.microsoft.com/v1.0/me/messages?$filter=conversationId eq '{conversation_id}'
Then order the messages by conversation index. The property conversationIndex does not support filtering on the server, so you need to order messages on the client as a string.
From ordered messages you are able to get the parent message.
There Isn't Any way to find parent_id by using reply mail response , In response provide parent_folderId but It Isn't useful to find parent_id
There Is one way to find parent_id If parent and reply messages have same conversation-id but Isn't then It cannot be possible to find the correct parent message

Graph API calendar endpoint doesn't support sending Adaptive card as attachment

We are using https://graph.microsoft.com/v1.0/me/calendar/events for creating Calendar events. What we are trying to achieve additionally is to send an adaptive card as attachment. We are using below code as POST body
{
"subject": null,
"body": {
"contentType": "html",
"content": "<attachment id=\"74d20c7f34aa4a7fb74e2b30004247c5\"></attachment>"
},
"attachments": [
{
"id": "74d20c7f34aa4a7fb74e2b30004247c5",
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": "{\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\",\"version\":\"1.5\",\"type\":\"AdaptiveCard\",\"body\":[{\"type\":\"Container\",\"style\":\"emphasis\",\"items\":[{\"type\":\"TextBlock\",\"text\":\"TheEYorganizationtodayannouncesthedetailsofthe52womenfounders\",\"wrap\":true},{\"type\":\"ColumnSet\",\"columns\":[{\"style\":\"default\",\"width\":\"stretch\",\"items\":[{\"type\":\"ColumnSet\",\"columns\":[{\"items\":[{\"type\":\"Image\",\"width\":\"200px\",\"url\":\"https://tse3.mm.bing.net/th/id/OIP._awI5wQIVTy1k8QdHtpSWQHaEK?w=292&h=180&c=7&r=0&o=5&dpr=1.3&pid=1.7\"}],\"type\":\"Column\",\"width\":\"auto\"},{\"items\":[{\"type\":\"TextBlock\",\"size\":\"Medium\",\"weight\":\"Bolder\",\"text\":\"SomeText\",\"wrap\":true},{\"type\":\"TextBlock\",\"size\":\"Medium\",\"weight\":\"Bolder\",\"text\":\"[https://adaptivecards.io](https://adaptivecards.io)\",\"wrap\":true}],\"type\":\"Column\",\"width\":\"auto\"}]}],\"minHeight\":\"100px\",\"type\":\"Column\"}]}]}]}",
"name": null,
"thumbnailUrl": null
}
],
"start": {
"dateTime": "2022-11-18T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2022-11-18T12:30:00",
"timeZone": "Pacific Standard Time"
},
"location": {
"displayName": "Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address": "xero.01234#contoso.com",
"name": "Orex"
},
"type": "required"
}
],
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness"}
Using above body, I am getting below error
{
"error": {
"code": "UnableToDeserializePostBody",
"message": "were unable to deserialize "
}}
As I understand this has something to do with the JSON I am passing as content inside attachment, I want to know if calendar invites endpoint supports adaptive card or not or is there any way, we can send adaptive card (using .NET SDK) to mail or events in outlook
Thanks, in advance
You can send actionable messages via emails only, see Supported scenarios for more information.

Microsoft Graph API - send message in channel by using team tagging

This graph API send a message in the channel
POST https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/messages
{
"body": {
"content": "Hello world"
}
}
Also, following the docs from https://learn.microsoft.com/en-us/graph/api/resources/chatmessagemention?view=graph-rest-1.0 I can mention user, channel or team
But I am looking for how I can mention Tags while sending message in a channel.
After doing some research, came up with a solution thought of posting here for others:
Graph API
POST https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/messages
Body here is critical
{
"subject": "This is very urgent!",
"importance": "urgent",
"body": {
"contentType": "html",
"content": "Programatically mentioning of Tagged users <at id=\"0\">String_1234</at>"
},
"mentions": [
{
"id": 0,
"mentionText": "String_1234",
"mentioned": {
"tag": {
"#odata.type": "#microsoft.graph.teamworkTagIdentity",
"id": "", //tag id
"displayName": "" //tag name
}
}
}
]
}

Are the organizer and isOrganizer Attributes in MS-Graph event working?

I'm trying to use the MS Graph API to create a new event with a technical user on behalf of a resource. The event is created, but the organizer and isOrganizer Attributes are not considered or ignored in the response.
I tried multiple requests as well as in 'v1.0' and 'beta' mode. In this SO question How to create event where current user not organizer using Microsoft Graph API it is stated that this is not implemented at the time of the original post (2016). But I didn't find anything in the Graph-API docs, saying that this would not work.
This is the request body:
{
"subject": "Instant Meeting: " + user_name,
"body": {
"contentType": "HTML",
"content": "Dieser Termin wurde vom Konferenzraum eingestellt"
},
"isOrganizer": "false",
"organizer" : {
"emailAddress": {
"address":user_email,
"name": user_name
}
},
"start": {
"dateTime": start,
"timeZone": "Europe/Berlin"
},
"end": {
"dateTime": end,
"timeZone": "Europe/Berlin"
},
"location":{
"displayName": room.get('name'),
"locationEmailAddress": room.get('email'),
"locationType" : "conferenceRoom"
},
"attendees": [
{
"emailAddress": {
"address":user_email,
"name": user_name
},
"type": "required"
},
{
"emailAddress": {
"address":room.get('email'),
"name": room.get('name')
},
"type": "resource"
}
]
}
The relevant parts of the response are:
response.get('organizer')
{'emailAddress': {'address': 'testraum-nichtbuche...t-mail.de', 'name': 'TestRaum - NICHT BUCHEN'}}
'emailAddress': {'address': 'testraum-nichtbuche...t-mail.de', 'name': 'TestRaum - NICHT BUCHEN'}
__len__: 1
response.get('isOrganizer')
True
If this worked properly, I would expect the 'organizer' to be user_email and the flag to be set to False.
Can anyone provide a working example for this?
Thanks!
This behavior has not changed. The organizer and isOrganizer properties cannot be defined by the caller, they are automatically assigned by Exchange:
setting event organizer with Outlook Calendar REST API
Outlook Calendar Rest API (create meeting using /me/events request with change organizer)
outlook.com rest api incorrect organizer email
How to create event where current user not organizer using Microsoft Graph API

Create a message with itemAttachment

Trying to send an email through Microsoft Graph where another email from user mailbox is to be used as an attachment.
What I am doing is something similar to:
POST https://graph.microsoft.com/v1.0/me/sendMail HTTP/1.1
authorization: bearer {access_token}
content-type: application/json
content-length: 96
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [{
"emailAddress": {
"address": "garthf#a830edad9050849NDA1.onmicrosoft.com"
}
}],
"attachments": [
"#odata.type": "#Microsoft.OutlookServices.ItemAttachment",
"name": "menu.txt",
"item": {
"id": "some_id"
<!--This is the id of an existing email in User's inbox -->
}
]
},
"saveToSentItems": "false"
}
This returns with
Cannot process input of abstract type Microsoft.OutlookServices.Item
Can anyone help with suggestions?

Resources