Quantcast
Channel: MSDN Blogs
Viewing all articles
Browse latest Browse all 29128

Forwarding a message as an attachment using Graph or REST

$
0
0

There isn't currently an easy way to forward a message as an attachment using REST, as the message: forward command does not have this option.  However, with the beta API, it is now possible to forward as attachment using the following technique.  Note that it is only possible to retrieve the MIME content of the message using the beta API.

Step 1: Retrieve the MIME content of the message being forwarded (note this is only possible using the beta API)

GET https://graph.microsoft.com/beta/me/messages/{id of message to be forwarded}/$value

The MIME content of the message is returned with this call.  This content will need to be Base64 encoded for use in step 3.

Step 2: Create a new message (the container for the forwarded message)

POST https://graph.microsoft.com/beta/me/messages
{
"subject":"Forwarding as attachment",
"body":{
"contentType":"Text",
"content":"Message attached"
},
"toRecipients":[
{
"emailAddress":{ "address":"1@demonmaths.co.uk"}
}
]
}

Step 3: Add the attachment (the MIME message) to the newly created message

POST
https://graph.microsoft.com/beta/me/messages/{id returned from step 2}/attachments
{
"@odata.type":"#microsoft.graph.fileAttachment",
"contentBytes": "{BASE64 encoded MIME, obtained from step 2}",
"contentId": "aouhfuqehwehighwri",
"contentLocation":null,
"contentType": "application/octet-stream",
"isInline": false,
"name": "message.eml"
}

Step 4: Send the message

POST https://graph.microsoft.com/beta/me/messages/{id returned from step 2}/send

Viewing all articles
Browse latest Browse all 29128

Trending Articles