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.