javascriptoutlookmime-typeseml

How to set sensitivity header in eml file for Outlook?


I'm trying to write an email via a dynamically created eml file with JavaScript.

I've modified this code to my needs from another SO answer but I'm not sure why Sensitivity and Priority headers are not working when I open the file with Outlook. In Outlook I see differently named sensitivity levels compared to rfc2156 (company set or Outlook?): "public", "internal", "confidential", and "strictly confidential". Not sure if that's important.

I've tried all possible combinations, with or without double quotes, etc but so far nothing seems to set either headers. I can see them If I read the eml in text editor but when I open the file in Outlook I just see the default settings being applied.

I'm using Outlook version 2102.

const emailBody = "<html><body><b>hello</b> world</body></html>";

let emlHeader = "data:message/rfc822 eml;charset=utf-8,";
emlHeader += `From: guy1@mail.io\n`;
emlHeader += `Subject: Sensitive message\n`;
emlHeader += `To: guy2@mail.io\n`;
emlHeader += `Bcc: guy2@mail.io\n`;
emlHeader += `Date: Sun, 10 Jul 2022 03:54:14 +0000\n`;
emlHeader += "Priority: Urgent\n";
emlHeader += "Sensitivity: Private\n";
emlHeader += "X-Unsent: 1\n";

const emlString = `${emlHeader}\n\n${emailBody}`;

const emlContent = encodeURI(emlString); //encode spaces etc like an url
const a = document.createElement("a"); //make a link in document
a.href = emlContent;
a.id = "fileLink";
a.download = "filename.eml";
a.style = "display:none;"; // hidden link
document.body.appendChild(a);
document.getElementById("fileLink").click(); //click the link

Solution

  • For PR_IMPORTANCE (possible values are IMPORTANCE_HIGH, IMPORTANCE_NORMAL, IMPORTANCE_LOW), you need X-Priority headers with values of 1, 2, and 3 correspondingly. You can also set X-MSMail-Priority header (Outlook specific) to High, Normal, Low.

    For PR_SENSITIVITY (possible values in MAPI are SENSITIVITY_PERSONAL, SENSITIVITY_PRIVATE, SENSITIVITY_COMPANY_CONFIDENTIAL), you need to set Sensitivity header to Personal, Private, Company-Confidential correspondingly.