7

I'm trying to use next API method: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#SendMessages. Sending messages without attachments works just fine, but I can not understand how to send message with attachments.

According to docs, Message structure can contain array of Attachments with items of type https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#RESTAPIResourcesFileAttachment . Problem is in the field ContentBytes -- it is impossible to dump bytes to JSON before sending request to this API method (actually dumping any BLOB to JSON is nonsense).

How should I pass Attachments using REST API at all?

Thanks.

Anton Koval'
  • 4,863
  • 5
  • 31
  • 44

2 Answers2

7

There's an example of passing the attachment on that page: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#SendMessageOnTheFly

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
0

I know I'm 3 years late but, you can look at this example: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#create-and-send-messages (if you don't get forwarded to the section "Create and send messages", please scroll manually). I know it is 365 and not Microsoft Graph but request is absolutely same. This is basically how JSON representation of the post method looks:

https://outlook.office.com/api/v2.0/me/sendmail

{ 
"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.FileAttachment",
        "Name": "menu.txt",
        "ContentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
      }
    ] 
}
}