Add information message when reading email - outlook

I would like to display an information message for the user when he read a specific email (i.e the email is tagged as external). The message should be displayed in the same way as outlook categories.
I know that I can use Exchange transport rule to achieve that but my client don't want to modify the message itself. He prefers displaying a message in the UI without changing the email body. The other option is to use the Office.context.mailbox.item.notificationMessages interface but as I told, I don't want to modify the email item if possible.
Do you think it is doable with outlook JS addins ?
My need is similar to this one for VSTO addin: How can my Outlook VSTO Add-in modify the read email form?

The Office.context.mailbox.item.notificationMessages interface provides the addAsync method which accepts the JSONMessage parameter which represents a JSON object that contains the notification message to be added to the item. It contains a NotificationMessageDetails object. Among properties you can find the persistent property which specifies if the message should be persistent. Only applicable when type is InformationalMessage. If true, the message remains until removed by this add-in or dismissed by the user. If false, it is removed when the user navigates to a different item. For error notifications, the message persists until the user sees it once. Specifying this parameter for an unsupported type throws an exception.
In case of categories, the message will be modified.
Do you know if it's possible to execute the function as soon as the read form is opened without having to click on an action button ?
Web add-ins are run under the context of currently selected item only. You can pin a task pane, then you'll be able to register an event handler to get notified of the change. The event handler should accept a single parameter, which is an object literal. The type property of this object will be set to Office.EventType.ItemChanged. When the event is called, the Office.context.mailbox.item object is already updated to reflect the currently selected item.
Office.initialize = function (reason) {
$(document).ready(function () {
// Set up ItemChanged event
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, itemChanged);
});
};
function itemChanged(eventArgs) {
// Update on the new current item
}

Currently the event-based activation of add-in in Read mode is not supported. We track Outlook add-in feature requests on our Tech Community Page. Please submit your request there and choose the appropriate label(s). Feature requests on Tech Community are considered when we go through our planning process.
Currently, Event-based of activation of add-ins is only supported for Compose mode. You can explore more here- Configure your Outlook add-in for event-based activation - Office Add-ins | Microsoft Docs

Related

How to fetch email internet headers in an on-send add-in?

We have a client that requires that an action take place when sending emails with certain Microsoft Information Protection/Azure Information Protection (MSIP/AIP) labels. We have a desktop Outlook add-in that does this perfectly.
Now however the client is requesting this same add-in but using the new modern style Outlook add-ins. We have created an on-send add-in to accomplish this, but we cannot get access to any internet headers in an Office.ComposeMessage. In fact, we cannot get any headers to be returned.
Here is our code:
async function fetchInternetHeaders(mailItem: Office.MessageCompose,
tags: string[]): Promise<string[]> {
return new Promise(function(resolve, reject) {
try {
let myTags: string[] = [
"msip_labels", // This is the value we need
"x-ms-has-attach", // This is for testing
"PR_SUBJECT_W", // This is for testing
"http://schemas.microsoft.com/mapi/proptag/0x0037001F", // test
"http://schemas.microsoft.com/mapi/proptag/0x5D07001F", // test
"http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels/0x0000001F", // Another way to get msip_labels
];
mailItem.internetHeaders.getAsync(myTags, function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
debug.Log("onSend.fetchInternetHeaders", "Selected headers: " + JSON.stringify(asyncResult.value));
} else {
debug.Log(
"onSend.fetchInternetHeaders",
"Error getting selected headers: " + JSON.stringify(asyncResult.error)
);
}
resolve(["FetchedInternetHeaders"]);
});
} catch (error) {
debug.Log("onSend.fetchInternetHeaders", "Error occurred", error);
reject(error);
}
});
Note: We ignored the parameter "tags" to make everything as simple as possible.
The call succeeds but the returned array is always empty, even for simple properties like the email Subject. What are we doing wrong?
Both COM add-ins and Web add-ins don't provide any internet headers until the message is sent out. You may expect the internet headers set when the message is put to the Sent Items folder, but before that they are not created and stamped by the service/transport provider.
Most probably you need to access user properties, see the UserProperties object in the Outlook object model. But the Office JavaScript API (OfficeJS) doesn't provide anything for that out of the box, you need to use EWS or Graph API to access such properties from web add-ins.
You can specify data specific to an item in the user's mailbox using the CustomProperties object. For example, your mail add-in could categorize certain messages and note the category using a custom property messageCategory. Or, if your mail add-in creates appointments from meeting suggestions in a message, you can use a custom property to track each of these appointments. This ensures that if the user opens the message again, your mail add-in doesn't offer to create the appointment a second time.
Be aware, changes to custom properties are stored on in-memory copies of the properties for the current Outlook session. To make sure these custom properties will be available in the next session, use CustomProperties.saveAsync.
These add-in-specific, item-specific custom properties can only be accessed by using the CustomProperties object. Like I wrote earlier, these properties are different from the custom, MAPI-based UserProperties in the Outlook object model, and extended properties in Exchange Web Services (EWS). You cannot directly access CustomProperties by using the Outlook object model, EWS, or REST. To learn how to access CustomProperties using EWS or REST, see the section Get custom properties using EWS or REST.
You can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team go through the planning process. Use the github label: Type: product feature request at https://aka.ms/M365dev-suggestions .

How to make ID what is returned by `Office.context.mailbox.item.ItemId` constant, so it is same in Compose and in Sent status of the email?

I'am developing addon for outlook. So for it I am using office.js api. In my addon I want the option to open emails in new window. I store emails ID in db.
Problem is that I "grab" Id of email when it is in compose status, for example, emails ID is AAA. I press sent btn and email now in Sent folder.
As it should, then I want to open that email using my addon, but I could not, reason that id of that email is now 'BBB'!
I checked it by pressing on that email in Outlook and calling this javascript code Office.context.mailbox.item.ItemId I found that email ID changed.
Question is how to make ID what is returned by Office.context.mailbox.item.ItemId constant so is the same in compose and in Sent status of the email?
In graph.api you have immutable ids but I do not see how to apply them in office.js.api
First of all, I'd recommend calling the Save method before retrieving the item Id. For example, the EntryID property available in the Outlook object model is set when an item is saved to the store.
Also different Outlook clients will return the itemId in the protocol they leverage. REST and EWS item Ids are escaped differently which is causing the difference between the itemId for the same item.
The id returned by Office.context.mailbox.item.itemId is an EWS item id. You can convert it to rest/graph item id by using Office.context.mailbox.convertToRestId.
In the desktop edition of Outlook the EntryId may be changed when an item is moved to another folder/store. Check it out whether this is the case.
Immutable ids are Graph specific. Ids in EWS (that is what JS addins use) and MAPI (used by both Extended MAPI - native Outlook API - and by the Outlook Object Model) change when an item is moved.
Your best option is to add your own custom property to the item and then search for it when the item in moved to a different folder.

Outlook New Message - Text Area Below Toolbar

I am creating an addin for Outlook.
I want to check some text on sending, but im not sure how to reference it
The text is in the image below and says “Attachment will be sent using...”
If the text equals the text displayed, i want to do something.
Thanks for any advice.
The Outlook object model doesn't provide anything for reading mail tips. But you may consider using EWS for getting mail tips. See Using MailTips in EWS to get the OOF (Out of Office) Status of users with C# and Powershell for the sample code.
FYI MailTips are informative messages displayed to users in the infobar in Outlook Web App and Outlook 2010/2013/2016 when a user does any of the following while composing an e-mail message:
Add a recipient
Add an attachment
Reply or Reply all
Open a message from the Drafts folder that's already addressed to recipients
To configure MailTips for mailboxes, external contacts, and distribution groups, in the Exchange Control Panel, select the mailbox, external contact, or distribution group, click Details, and then in the MailTip section, create the MailTip.
To configure MailTips for mail users and dynamic distribution groups, in Windows PowerShell, use the MailTip parameter on the Set-MailUser and Set-DynamicDistributionGroup cmdlets.
Regardless of whether you use the Exchange Control Panel or Windows PowerShell, two things always happen when you add a MailTip to a recipient:
HTML tags are automatically added to the text. For example, if you enter the following text: This mailbox is not monitored. The MailTip automatically becomes the following: <html><body>This mailbox is not monitored.</body></html>
The text is automatically added to the MailTipTranslations property as the default value. If you modify the MailTip text, the default value is automatically updated in the MailTipTranslations property.
Read more about that in the Configure MailTips article.

Outlook Addin - Wait for a response

I have an Outlook Addin that creates a contact on a webpage by making an API call to that webpage. When the Addin runs (via the click of a button), the API call is made and the user is taken to that webpage to fill in the contact information. After the user has filled in the information and clicks on submit, I would like to catch that event in Outlook and get the user back to Outlook to carry out further actions. Any possible ways of getting this done? I've been looking online but haven't found any solution as such.
Try to display the web page in a modal dialog in your own form. When the form is closed, you can take whatever action is necessary.
You may find the ItemSend event of the Application class helpful. It is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program.
Also you may consider repurposing ribbon controls. See Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.

Can I override the default "Drag and Drop" behaviour when dragging email item from outlook?

After dragging email item from outlook, my own application (written in C#) can get the data and retrieve the msg data when the email item is dropped on it. But is it possible to override the default "drag and drop" behavior so that I can send some information else (rather than the default information) when dragging an email item and pick up the information when the item is dropped on my own application?
No - there might be some very ugly hacks, but no usable approach.
What you could do though is utilize something from the mail in information you receive via Drag'n'Drop as a unique identifier somewhere in the mail information that gets transmitted.
With the ability to identify the mail in Outlook you could e.g. connect to Outlook via automation or use a minimal Outlook AddIn that can be queried for what you need.

Resources