Outlook Mail REST API: send message with attachment
Asked Answered
L

2

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.

Laundryman answered 25/8, 2015 at 7:43 Comment(0)
E
7

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

Efren answered 25/8, 2015 at 12:7 Comment(0)
T
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": "[email protected]"
        }
      }
    ],
    "Attachments": [
      {
        "@odata.type": "#Microsoft.OutlookServices.FileAttachment",
        "Name": "menu.txt",
        "ContentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
      }
    ] 
}
}
Tellez answered 18/4, 2018 at 10:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.