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? - outlook

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.

Related

How to get itemId of the item you are replying/forwarding to using Office-JS

Is there a way to get the itemId of the item you are replying/forwarding to in compose mode using the Office-JS library or EWS? I want to be able to get the itemid of the email or meeting invite that I am replying/forwarding.
OfficeJS doesn't provide anything for that. Basically your add-in is run under the context of a specific item in Outlook (currently selected). The best what you could do is to use EWS by calling Office.context.mailbox.makeEwsRequestAsync or Graph API (for Office365 users). You may take a look at the EWS - Determine if an e-mail is a reply or has been forwarded thread, you are interested in getting the In-Reply-To field. Note that In-Reply-To is an optional field so it may not always be populated.

Redemption attachement filename escaping differs from Outlook

We are trying to save attachments selected by the user using Redemption but stumbled on filename escaping inconsistency between VSTO and Redemption. What we do:
By attachment context menu save attachmentSelection[1] index and filename to the db and also message entryId and storeId.
After a while (maybe even after Outlook restart) we need to save this attachment to file. To do this, we get that e-mail with Redemption by id, get attachment by index (rdoMail.Attachments[index]) and also ensure that filename match, since according to this:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.outlook.attachment.index?view=outlook-pia#Microsoft_Office_Interop_Outlook_Attachment_Index
index property is valid only during the current session. Although it is not clear what they mean. Can it change if the e-mail is saved and sent already? Or received?
For reply e-mail VSTO Attachment.Filename is "RE Test.msg" and RDOAttachment.Filename is "RE_ Test.msg" (this is msg attachment of another e-mail).
So, the questions are:
why it is different and is it documented somewhere? Can we, for example, replace _ with string.Empty for Redemption filenames or there can be other cases?
Or maybe there is a way to get RDOAttachment from Outlook Attachment object somehow?
Can we rely on that Redemption attachment index is the same as Outlook one?
Sounds like you are dealing with an embedded message attachment - unlike regular by-value attachments that expose the PR_ATTACH_LONG_FILENAME MAPI property, there is no intrinsic file name property for the embedded attachments. Both OOM and Redemption generate that property from the the embedded message subject, whcih you cam access through RDOAttachment.EmbeddedMsg.Subject. OOM does not expose embedded message attachments at all.
Yes, use RDOSession.GetRDOObjectFromOUtlookObject method
The index usually does not change, but it might. MAPI itself uses PR_ATTACH_NUM to open the attachment using IMessage::OpenAttach, but it can be different based on how the message was opened - a fake IMessage returned from MailItem.MAPIOBJECT can have a different value of PR_ATTACH_NUM from the native message returned by the store provider.

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.

Setting Activity Category on Email tracked from Outlook to CRM

I'm using Dynamics CRM 2015 (7.0.2.53) and Outlook 2016 (16.0.7766.7080) with the CRM for Outlook (7.1.1.3113) addin.
What I am trying to achieve is to give users the ability to specify an Activity Category against an email which they Track and Set Regarding from Outlook.
Currently, upon tracking and setting regarding on an email in Outlook, an Email Activity is created against the specified Entity record (let's say an Opportunity) in CRM, which is fine. The problem is that I cannot find any way to allow the user to specify an Activity Category for that created Activity either during the Track/Set Regarding process, or even after the Activity is created in CRM.
Is what I'm trying to achieve possible and if not, is there any other way to achieve a similar result, so that users can specify some value from a set of options against an email when they track it from Outlook to CRM, so that value can then be used for reporting purposes?
Basically there is no way of adding some custom functionality to Tracking Emails from Outlook. So you cannot add anything in Outlook plugin that will allow you to perform some operation on CRM side to set the Category right.
You can always make a plugin/workflow on Email creation in CRM and based on some email properties (topic, content, recipients etc.) set this category by youself - but of course users still will be unable to change it.
When email is created in CRM, it's disabled (because it usually already has been sent), but you can still modify it using workflows and dialogs. So you can always create a Dialog (https://msdn.microsoft.com/en-us/library/gg509010.aspx) and there you can prompt for proper category and set it on the email. So I can see a scenario like that - you have a view of Emails that are not categorized (or a Queue, where you put them in a plugin when user is tracking email from outlook). You pick Email, click "Start Dialog" which will be called "Set Category" or whatever, and set the category. Of course after this operation Email will vanish from the view. You can always create a reminder for the users to set the category for their mails, this should be included in new users training etc. Without any hardcore custom coding I think that's the only thing you can do (because if you don't mind writing more complex stuff you can always prepare some custom HTML5 control on Email form that will allow you to set the category field).

Get/change safe senders list and blocked senders list in C# VSTO

I'm working on an Outlook 2010 add-in that needs to prompt users before following a link found in an email. During the process I'd like to offer the user the choice to trust or block the sender of the email, thus I need to access both lists. I realize that Junk/Spam email options are not exposed by Outlook OM. Although I was successful in accomplishing the task using Redemption, unfortunately I'm not allowed to use it by my employer, so I need to find another way. I found this post (Get Safe sender list in Outlook 2007 C# Add in) that points in the direction of either MAPI properties or registry keys.
My preference would be MAPI props, but I'm not sure what object that property belongs to. Would it be the property of the default store?
Outlook.Store obj = Application.Session.DefaultStore;
const string PR_SPAM_TRUSTED_SENDERS_W =
"http://schemas.microsoft.com/mapi/proptag/0x001f0418";
Outlook.PropertyAccessor pa = obj.PropertyAccessor;
string list= pa.GetProperty(PR_SPAM_TRUSTED_SENDERS_W).ToString();
Unfortunately I'm getting an error message (translated to English) like 'Object doesn't have such property'. In production it would have to work with Outlook clients connected to Exchange 2007 mailboxes.
Ok found it. The actual property is called PidTagExtendedRuleMessageCondition and the Blob format is described here MS-OXCSPAM and in MS-OXORULE respectively.

Resources