First published on TECHNET on Dec 14, 2017
This post is a contribution from Manish Joshi, an engineer with the SharePoint Developer Support team
The purpose of this blog is to walk through the process of calling the Outlook Mail API to send messages in Office 365 and Outlook.com. These guide focuses on the OAuth and REST requests and responses. It will cover the sequence of requests and responses that an app can use to authenticate and send an email messages with file attached from a SharePoint Online list item.
Authentication is covered under:
Note : The outlook endpoint used in this guide https://outlook.office.com/api/beta is beta endpoint and should not be used in Production.
The following sections demonstrate sending an email with attachment from SharePoint Online using the Outlook REST Endpoint. This involves 3 steps which are listed below.
POSTMAN calls :
Step 1: Creating an email message
This is a POST request to the endpoint https://outlook.office.com/api/v2.0/me/MailFolders/inbox/messages . The body of the request will contain details like subject, email body and recipient email address. Note the Id returned in the response. This will be used for subsequent requests.
Step 2: Adding an Attachment to the previously created email
This is a post request to the endpoint https://outlook.office.com/api/beta/me/messages/<<messageID>>/attachments . <<messageID>> is the ID retrieved from Step 1. The body of the request will contain the path of the file In SPO/ODB to be attached.
https://outlook.office.com/api/beta/me/messages/ AQMkADcwMzljMTUzLTJlMDktNGFiNy1hYzUwLWU5OGYzNzZiMWY1MABGAAADKqbIbNdyOUuJz-wQyvCCegcA_LuhL0sY6EWHV1FbpHFFhAAAAgENAAAA_LuhL0sY6EWHV1FbpHFFhAAD8kJ2LgAAAA==/ attachments
Step 3: Sending the email
The previous two steps involved creating an email message and adding an attachment. The final step is to send the email message. This is a post request to the endpoint https://outlook.office.com/api/beta/me/messages/<<messageID>>/send . The request and response body are empty in this case. The status will be "202 Accepted" if the email message has been successfully sent
https://outlook.office.com/api/beta/me/messages/ AQMkADcwMzljMTUzLTJlMDktNGFiNy1hYzUwLWU5OGYzNzZiMWY1MABGAAADKqbIbNdyOUuJz-wQyvCCegcA_LuhL0sY6EWHV1FbpHFFhAAAAgENAAAA_LuhL0sY6EWHV1FbpHFFhAAD8kJ2LgAAAA== /send
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.