Save mail to inbox using Graph API, similar to Exchange Web Services (EWS) API

Zack 31 Reputation points
2022-11-24T15:33:24.86+00:00

I have a multitenant Microsoft application that is authorized via the client credentials oauth 2 flow. The app needs to be able to create an email with attachments, and place that email into a user's inbox. The application is using the EWS Managed API, and is calling CreateItem to create an email message, as well as CreateAttachment. Both calls are done using ExchangeImpersonation. The application works as intended, but it currently requires the full_access_as_app permission. This feels far too permissive. I have posted about this issue here.

I am trying to migrate to the Graph API, as I am hoping that Microsoft would be willing to add more granular permissions there. However, it does not seem the Graph API supports what I am trying to do. I can call the create message endpoint (https://learn.microsoft.com/en-us/graph/api/user-post-messages?view=graph-rest-1.0&tabs=http), but I cannot manage to put the mail into inbox (rather than draft). I also am unable to set the from mailbox to any sender I want. Both of these things are possible via the EWS API.

Does anyone know if there is a way to achieve this via the Graph API?

Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
508 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Glen Scales 4,431 Reputation points
    2022-11-27T22:58:57.663+00:00

    You need to set a few Extended properties to do this you need to set the MessageFlags extended property to make it appear as if it was a Sent Message. You also need 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 to the date you want the message to be sent.

    {  
        "Subject": "Test123",  
        "Sender": {  
            "EmailAddress": {  
                "Name": "senderblah",  
                "Address": "senderblah@blah.com"  
            }  
        },  
        "Body": {  
            "ContentType": "HTML",  
            "Content": "Just the facts"  
        },  
        "ToRecipients": [  
            {  
                "EmailAddress": {  
                    "Name": "blah",  
                    "Address": "blah@blah.com"  
                }  
            }  
        ],  
        "SingleValueExtendedProperties": [  
            {  
                "Id": "Integer 0x0E07",  
                "Value": "1"  
            },  
            {  
                "Id": "SystemTime 0x0039",  
                "Value": "2022-11-27T09:55:38.7169+11:00"  
            },  
            {  
                "Id": "SystemTime 0x0E06",  
                "Value": "2022-11-27T09:55:38.7169+11:00"  
            }  
        ]  
    }  
    
    1 person found this answer helpful.