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

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.

Related

Changing Account with "on-send" feature?

I have a customer with multiple users, they have two emails accounts on two differents domains.
One is managed by Office365 : Teams / Calendar, example : #my-business.com
Second is for "secure" communication, exemple : #my-secure-email.com
The second one is really not used very often but the emails sent or received must absolutely not go on Office365 (legal reason)
I want to force user to send emails to *.#my-secure-email.com with second account.
With "on-send Feature" i think i can "block" emails but ideally it should be possible to dynamically change the account used in Outlook according to the recipient's address ?
EDIT to clarify :
Is it possible to change sender account with office-js and "on sender" feature on office365 ?
Is it possible to change sender account direclty in Outlook for Windows based on recipient address ?
Thanks
Guldil
Is it possible to change sender account with office-js and "on sender" feature on office365 ?
No, it is not possible. OfficeJS doesn't provide anything for that.
Is it possible to change sender account direclty in Outlook for Windows based on recipient address ?
Yes, you can choose the sender's account in Outlook manually or by using a VSTO add-in instead. The MailItem.SendUsingAccount property is available in the Outlook object model (available for VBA macros and COM based add-ins). The property allows setting an Account object that represents the account under which the MailItem is to be sent.
But web add-ins work under the context of currently selected item only (or in case of UI-less add-ins what they activated for) and don't provide access to application-wide features like choosing email account to send from.
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 .

VSTO Identify shared vs User mailbox

In a VSTO add-in, I am trying to retrieve if the type of the mailbox is shared, user or resource.
I read some interesting posts related to the question and try to look at the OlExchangeStoreType or GetConversation or MailboxType but did not succeed.
I have seen the solution (3) from #DmitryStreblechenko but I would prefer to not use EWS if possible.
It seems that the value that I am looking for is the msExchRecipientTypeDetails.
Any help would be highly appreciated.
Relevant articles
EWS Get mailbox type (user/resource/shared)
MailItem.GetConversation() on shared mailbox
In Outlook Addin, how do I determine if an email's Sender is a shared mailbox email address?
https://www.codeproject.com/Questions/1088741/How-to-list-subfolders-in-inbox-folder-in-shared-e
https://learn.microsoft.com/en-us/answers/questions/612248/in-outlook-addin-how-do-i-determine-that-an-email.html
First of all, VSTO doesn't provide anything for that.
Second, the Outlook object model doesn't differentiate shared/local stores. So, you will not find any property or method for that in the OOM. The best what you could do is to use the Store.ExchangeStoreType property which returns a constant in the OlExchangeStoreType enumeration that indicates the type of an Exchange store.
It is up to you which way/workaround is to use form the list shared above.
You don't need to use EWS - try to read Namespace.AutoDiscoverXml property to check if the shared mailbox and its type are there - you can see it in OutlookSpy (I am its author): click Namespace button, select AutoDiscoverXml property.
Look for the AlternativeMailbox\Type nodes - you can have "Archive", "Delegate", "TeamMailbox".

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.

How do I get the memberships (distribution groups) of an Outlook contact programmatically?

Using office Outlook, we can find the 'Memberships' tab when we click and expand a contact, this 'Memberships' tab shows the list of emails that the user is subscribed to.
For example, Employee X (x.x#zcompany.com / id123#zcompany.com) under the Data Department of Z Company is subscribed to the following distribution groups:
datateam#zcompany.com
allemployeees#zcompany.com
dataweekly#zcompany.com
it.uk#zcompany.com
znewsletter#zcompany.com
I would like to get the list of emails the user is subscribed to by inputting either the user's email or user's organization ID.
I found a few potential solutions but do not know exactly how to implement them:
Outlook Interop GetMemberOfList() and GetExchangeDistributionList()
Using Microsoft Graph API
VBA automation for Outlook
Reverse engineering using ExchangePowershell
Using RPA to imitate user actions on Outlook
Wonder if someone with experience doing this can provide some advice? Thanks in advance.
In OOM, call Application.Session.CreateRecipient, Recipient.Resolve, Recipient.AddressEntry.GetExchangeUser(). ExchangeUser exposes GetMemberOfList() method, which returns IAddressEntries object.

Email thread detection in an Outlook add-in?

I'm designing an Outlook add-in and need to determine whether a selected message is part of a thread. Ideally, I'd also like to find related messages in said thread as well. Reading over the documentation, the conversationId property looks promising, though there doesn't seem to be a way to "get messages by conversationId."
Under the current version (1.4, non-preview) of the Outlook Add-in API, is it possible to detect that a message is part of a thread using the JavaScript API? Is it possible to then find other messages in the same thread?
ConversationId is part of the javascript API. This means that you can know the ConversationId for the Office.context.mailbox.item whose your add-in is focusing on. See documentation here
To my knowledge, there is no way to retrieve all mails for a given ConversationId using vanilla javascript and Office.js.
However, you may be interested in my answer here.
When something is not available with Office.js api for an Outlook
Add-in you can try to use the Exchange Web Services (EWS) or REST APIs to perform the action
You have basically two ways to request EWS from a mail add-in.
You can request directly the EWS with a SOAP request from your client
app. See method makeEwsRequestAsync in Office.context.mailbox(https://dev.outlook.com/reference/add-ins/Office.context.mailbox.html).
You can get an access token, send it to your server and make the request from
there.
For the specific case of retrieving conversations using the Outlook REST API, this answer may also be helpful.

Resources