0

Requirement: When admin receive an email from client, he/she can send the email body(content) to our business app and store there for the future reference.

Issue: When we used Office.context.mailbox.item.body.getAsync() we are getting 2 different format html from web and outlook desktop app. This is causing issue for us in our Business API.

Outlook Web Response:

<div>\r\n<div>\r\n<p></p>\r\n<div style=\"color:black;font-size:10pt;font-family:Calibri;text-align:left;background-color:#FFEB9C;width:100%;padding:2pt;border:1pt solid #9C6500;line-height:12pt;\">\r\n<span style=\"color:#9C6500;\">CAUTION:</span> This is an EXTERNAL email.</div>\r\n<br>\r\n\r\n<p></p>\r\n<div>\r\n<div dir=\"ltr\">Test</div>\r\n</div>\r\n</div>\r\n</div>\r\n

Outlook Desktop (Mac) Response:

<html><head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><p></p><div style=\"background-color:#FFEB9C; width:100%; border-style: solid; border-color:#9C6500; border-width:1pt; padding:2pt; font-size:10pt; line-height:12pt; font-family:'Calibri'; color:Black; text-align: left;\"><span style=\"color:#9C6500\" ;=\"\" font-weight:bold;=\"\">CAUTION:</span> This is an EXTERNAL email.</div><br><p></p><div><div dir=\"ltr\">Test</div></div></body></html>

We need only 1 format(preferably Outlook Web html output) from all the outlook client. How to get the same on Outlook Desktop App and Outlook Mobile App ?

Update

Solution/Hack: I made the below changes and it worked for me:

Step - 1: Remove the newline characters

const htmlSting = html.replace(/(\r\n|\n|\r)/gm, "");

Step - 2: Extract only required Block

const reg = /<div[^>]>([^])</div/m;
const requiredString = htmlSting.match( reg )[1];

I've referred below stack-overflow answer: How to remove whole HTML, HEAD tags and BODY tag from string with HTML using JavaScript?

thanks to @thomthom.

halfer
  • 19,824
  • 17
  • 99
  • 186
Gurudeepak
  • 372
  • 2
  • 14
  • Not a duplicate, but follow this to see if it helps: https://stackoverflow.com/q/36499958/1690217 – Chris Schaller Jan 13 '21 at 05:45
  • Please show the actual code you have tried, this post might also help: https://stackoverflow.com/a/52980781/1690217 - in general it might be easier to simply support parsing the two formats on your API side – Chris Schaller Jan 13 '21 at 05:51
  • 1
    My final advice is that you send the message id to your API, then in the API retrieve the message independently from the exchange server, that way you do not have to update your add-in every time you need to make a change to the implementation. The addIn is a simple wrapper that passes minimal information to your API – Chris Schaller Jan 13 '21 at 05:54
  • @ChrisSchaller, Thanks for the advice. We will try to implement the same. – Gurudeepak Jan 13 '21 at 06:05
  • @BabyYoda, Try getting mail body content using `Graph API` instead of `getAsync()` function. You can see the document here - https://learn.microsoft.com/en-us/graph/api/message-get?view=graph-rest-1.0&tabs=http – robdev91 Jan 13 '21 at 18:54
  • @BabyYoda, Or you can refer to this document. https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/use-rest-api Use Outlook REST API to fetch the message content. – robdev91 Jan 13 '21 at 19:11

0 Answers0