2

I am trying to add an existing email item as an attachment to a new message. The goal is to have my Outlook plug-in forward the currently-selected email as an attachment for further review by someone else.

Here is basically how I do it:

  1. Obtain the ID for the mailbox item I want to forward:

    var itemId = Office.context.mailbox.convertToRestId( Office.context.mailbox.item.itemId, Office.MalboxEnums.RestVersion.v2_0)

  2. Get the message using this URL:

    var getMessageUrl = Office.context.mailbox.restUrl + '/v2.0/me/messages/' + itemId

  3. Use this for the attachment in this call:

    "Message": { "Subject": "Spam Email :" + response["Subject"], "Body": { "ContentType": "text", "Content": "Test of Office add-in." }, "ToRecipients": [{ "EmailAddress": { "Address": to } }], "Attachments": [{ "@odata.type": "#Microsoft.OutlookServices.ItemAttachment", "ContentType": "JSON", "Name": response["Subject"] + ".eml", "Id": itemId }, "SaveToSentItems": "false"

I get an error when I do this. I've even tried passing the response I get from the first REST call to obtain the original error. It doesn't like the format of the data I'm passing in even though I pass it verbatim as I received it.

The only way I have gotten this to work is to manually create a new attachment using all of the fields from the response. However, this does not preserve the original email's headers (something I need to send over for review). It also leaves the email in draft/unsent mode (ie, when I open it the editor is ready to edit and send it as opposed to how the editor looks when opening an email that has already been sent).

Is there a way to just tell the API to fetch the attachment? Why do I have to pull the data down and then send it back up?

I reviewed this SO post already but need more assistance:

https://stackoverflow.com/a/46954993/267702

gonzobrains
  • 7,856
  • 14
  • 81
  • 132

0 Answers0