0
votes

I'm working on an Outlook Add-in, using office.js, where users can send secure emails using backend service.

In compose mode, when the user sends the email, using the add-in of course, the add-in will then move the message to "Sent Items" folder using the Outlook API /message/{id}/move and everything goes OK with the exception that the message in question still being marked as "Draft" by Outlook which is really annoying and does confuse the user who just sent the email by telling him that "this message hasn't been sent"

enter image description here

I searched through the API to see if there is a way to mark an email as "SENT" in order to prevent Outlook from showing this RED hint but with no luck so far!

So, My Question Is: Is there any way to overcome this misleading msg by marking the email as it was sent by Outlook?

Thanks in advance.

1
I don't think it is possible, the properties that look promising are readonly. Look at creating a separate message to store in the Sent Items. I have not tried this before. Look here: social.msdn.microsoft.com/Forums/office/en-US/… - " If you want the message to appear as its been sent (rather then appearing as a draft). Then when you create the message with EWS you need to set the MessageFlags extended property. Its important to set it at creation time..."Brian Clink
What APIs are you using to send the message using the Add-in?Outlook Add-ins Team - MSFT
@OutlookAdd-insTeam-MSFT, it's a 3rd party API and not the Outlook APIReda Beloued
@BrianClink, Thanks Brian, your comment was very insightful although I couldn't achieve what I wanted. This answer here stackoverflow.com/questions/49008005/… provides a quasi-solution for me which proposes adding this: 'singleValueExtendedProperties': [{'id':'Integer 0x0E07','value':'1'}] which worked perfectly in Graph Explorer but failed in Outlook Mail API where it says 'singleValueExtendedProperties' does not exist. I really don't want to use the Graph API for just a simple action like this!Reda Beloued
If it is a limitation, you could request an enhancement via user-voice officespdev.uservoice.com/forums/224641-general/category/…. The Outlook JS API may not be suited for this type of complex operation. You may need to use a combination of both Outlook JS API and Graph API. For Graph, you can create the app reg in your own tenant, although your customers can't pre-authorize the app on their user's behalf. We find this useful for evaluations, and when the app is deployed to a company, they will deploy their own app reg.Brian Clink

1 Answers

0
votes

Finally, I was able to achieve a perfect solution for this challenge.

Based on:

The approach/steps I followed to mark a mailItem as "SENT" (and not shown as 'draft') and put it in "SentItems" Folder are as follow:

  • First, Save the mailItem as "draft" using Office.context.mailbox.item.currentMail.saveAsync then retrieve its ID
  • Clone this draft mailItem properties eg: 'Sender', 'Subject', 'Body', 'ToRecipients'..etc so you get an exact copy of it.
  • With the newly cloned mailItem, add '[SingleValueExtendedProperties]' property with this value :
[
  {
     PropertyId: 'Integer 0x0E07',
     Value: '1'
  }
];
  • Serialize the new item as JSON and POST it to "sentitems" folder as follows:
xhr.open('POST', restHost + '/v2.0/me/MailFolders/sentitems/messages/');
xhr.send(clonedEmailJson);
  • On success, with xhr.status=201 [created], Remove the draft mailitem using a [DELETE] request

And you will end up having a new mail item created in your "sentItems" folder which appears as it was sent by Outlook :)

This was a very helpful solution to me because my users are using my add-in to send secure emails (using 3rd party API) and NOT Outlook, So, I wanted them to have the same UX/feeling as when they use Outlook.

Note:

Although the solution worked for me perfectly, it came with a price! On slow internet connections or in case emails containing large attachments, the process can be remarkably slow, because the addin will first save the draft to the remote Exchange Server, get its ID, then duplicate it and send it again to the server, then remove the draft-ed one.