VSTO Outlook ItemAdd is not fired on Outlook 365 startup for emails received while Outlook was off - outlook

I wrote a VSTO add-in for Outlook. I am in a Microsoft Exchange environment in my company. The add-in responds to new email messages with the ItemAdd event. With Outlook 2013 this worked without problems. Especially when emails were received while Outlook was not started. When Outlook started, an event was fired for each new mail item and everything was fine.
The company has now switched to Office 365.
I have now noticed that Office 365 does not generate any events for newly received emails while Outlook is not running.
As a workaround, I created a rule that moves emails from the default inbox to other folders. I also monitor these other folders for new emails. With this mechanism, I also recognize new emails that have arrived while Outlook was not active.
I don't find this workaround particularly elegant.
The ItemAdd event doesn't seem to trigger events with Outlook 365 for mail (arrived when Outlook is not active) for me when Outlook starts.
Does anyone have any idea how I can create events in Outlook 365 (other than my cumbersome workaround) for emails that came in while Outlook was off?

Items.ItemAdd event won't fire if you are using online mode - the event only fires as Outlook synchronizes its OST cache with the server and newly created messages are downloaded and added to the folder.
Another possibility is that the folder is synchronized before your addin is loaded.
Keep in mind that all Outlook (and MAPI) events were only designed for the UI purposes - they are not guaranteed to fire and can be skipped under heavy loads.
Also note that that if too many items are added/modified/deleted at the same time, folder contents table will fire TABLE_CHANGED or TABLE_RELOAD MAPI event, which (unlike TABLE_ROW_ADDED / TABLE_ROW_DELETED / TABLE_ROW_MODIFIED events mapped to ItemAdd / ItemRemove / ItemChange in OOM correspondingly) is not exposed by Outlook at all. If using Redemption is an option (I am its author), it exposes RDOItems.CollectionModified event (raised when TABLE_CHANGED or TABLE_RELOAD are fired).
Ultimately, if you are using events for any kind of synchronization rather than UI, the events can at best serve as a hint that you need to process the folder sooner rather than later. Each time you process an item, you can store the latest item creation/modification time, then on startup, retrieve all items newer than that time stamp using Items.Restrict or Items.Find/FindNext. Keep in mind that all date/time values in OOM (but not in MAPI or Redemption) are rounded to a minute, seconds and milliseconds are always 0.

Related

Is it possible to detect when the user changes the date of an appointment directly from the calendar?

I am writing an outlook web Add-In where the user can create an appointment and book a meeting room through the software.
The problem is that once the user closes the Add-In and goes back to the calendar, they can freely change the date of the appointment by dragging it around, and the Add-In cannot see those changes, since it's not open.
That means that those changes do not get registered into the system and are essentially only local to the user who made them. I need a way that I can detect whenever the user changes the date of an appointment, so that I can update the data on my end.
I have heard about subscribing to notifications but I'm not sure that is the best solution. Any Ideas would be highly appreciated.
Not from a web addin - you can do that from a standalone app that continuously runs and uses either the Outlook Object Model (Items.ItemChange event) or EWS to receive the folder notifications. Or you can do that from a COM addin that uses the Items.ItemChange event.

How to send appointment through Outlook add-in?

I'm trying to implement an add-in for Outlook which has some fields and a button that once clicked does some validations and sends an appointment to inform the attendees.
I am using the function below to achieve my goal:
Office.context.mailbox.item.saveAsync()
Office.context.mailbox.item.close() (as a callback for the function above)
It works for office365, but it doesn't work for office365 thick client.
I found in the Microsoft docs that with the function 'saveAsync' in Outlook in cached mode, the item is saved to the local cache. I disabled this option and still getting the same result.
I was using OnSend functionality, but this feature is not supported for Outlook client.
Any advice or tips of how could I have the functionality of sending the appointment through my Add-in in both, client and web version of Outlook? Basically I need to trigger the existing button 'Send' in the calendar.
It sounds like the ItemSend Event (OnSend) you are using in Outlook on the Web handles your scenario. We are working to bring this functionality to Outlook on Windows soon.

Outlook plug-in

I'm looking build an outlook addin that can do the following. Would like to hear tips from anyone who might have done this before.
Upon install, read the person's profile in outlook and call a service which will create an account for that person in my app
When person sends an email from outlook with a .pptx/.ppt file(s) attached, it calls a service to automatically upload that file(s) into my app.
Upon install, read the person's profile in outlook and call a service which will create an account for that person in my app
You can use Namespace.CurrentProfileName property introduced with Outlook 2007.
When person sends an email from outlook with a .pptx/.ppt file(s) attached, it calls a service to automatically upload that file(s) into my app.
The Application.ItemSend event 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. So, in the event handler you can check the Attachments collection for the files specified and do your web calls.
See Walkthrough: Creating Your First VSTO Add-In for Outlook to get started quickly.

How can we force a mailbox item to be persisted to EWS?

Note: This particular issue has significant impact on our customers, which translates to high business impact with direct consequences on revenue.
TL;DR.
How can our Office add-in for Outlook, when a user interacts with our add-in while composing an email draft, minimize the amount of time it takes before the EWS GetItem API will return an OK response for the itemId we receive from Office.context.mailbox.item.saveAsync()?
If it turns out that our add-in has no control over when the item will be persisted to EWS, then what could an end-user do to speed this up?
We are looking for either (a) a technical solution, or (b) messaging to instruct our customers on how to mitigate/fix/work around this issue.
End-User Impact
Some of our customers are unable to send emails using our Office add-in for Outlook, or have to wait an exceedingly long time (> 2 minutes) before their email will send.
Our Goal
We want all of our customers to be able to send emails using our add-in, without having to wait for an unreasonable amount of time.
Additional Context
Based on our logs and customer reports, this issue only exists in the Outlook 2016 for Windows desktop application. We have no evidence to suggest the issue is present in any other version of Outlook, including Outlook 2013 or Outlook for Mac, however it is possible that the issue may be present in those clients as well.
Overview of our add-in
Our add-in integrates with Compose mode to provide additional functionality while composing email messages, such as templates, follow-ups, open and click tracking, and scheduling.
Our add-in works in tandem with our SaaS product like this:
Our add-in sets EWS extended properties on the email message with metadata indicating which features are enabled on that message.
Our SaaS product, out of band, is configured to read from the customer's mailbox via the EWS API. When it encounters EWS extended properties our Office add-in has written, it triggers the code paths to satisfy the desired behavior.
Root Cause Analysis
The root cause of our problem is our interaction with EWS in Outlook 2016 for Windows. In order to successfully interact with EWS to read/write to a mailbox item, it must be aware of that item.
The documentation for Office.context.mailbox.item.saveAsync() says:
In Outlook Web App or Outlook in online mode, the item is saved to the server. In Outlook in cached mode, the item is saved to the local cache.
It goes on further to say:
Note: If your add-in calls saveAsync on an item in compose mode in order to get an itemId to use with EWS or the REST API, be aware that when Outlook is in cached mode, it may take some time before the item is actually synced to the server. Until the item is synced, using the itemId will return an error.
Thus, we have concluded that Office.context.mailbox.item.saveAsync(), although it does indeed return an eventually valid itemId, does not guarantee that any subsequent EWS interaction will succeed. So far, we have found no way to accelerate the process of the Outlook client actually making EWS aware of the mailbox item.
Mitigation
We have attempted to mitigate this problem by polling EWS GetItem to attempt to obtain a ChangeKey for the item with the itemId we receive from Office.context.mailbox.item.saveAsync(). While we have seen that this does eventually succeed, it may take a minute or longer before this occurs. That is simply far too much time for our customers to have to wait.
Understanding "online mode" vs "cached mode"
If the Outlook 2016 for Windows desktop client is in "cached mode", is there anything the user can do to:
…know whether the client is in "cached mode" or "online mode"?
…attempt to force the client into "online mode"?
There is no way to speed this up in cached mode. Unfortunately this is a limitation of saveAsync in compose mode. Some things of note:
1) The EWSId is only valid while the item is a draft. After it is sent, when the item is in sent items, it will have a new EWSId which is not obtainable from the Office.js
2) Could you save your information into the custom properties, instead of the EWS Extended Properties. (Office.context.mailbox.item.customProperties) https://dev.office.com/reference/add-ins/outlook/1.5/CustomProperties?product=outlook
These properties will be saved to the mail in the sent item, but will NOT be transmitted. Then could you find those properties
These are stored as a JSON dictionary on the item in Key/Value pairs. The name of the mapi property is "cecp-[extension id from manifest]" (in PS_PUBLIC_STRINGS)
https://msdn.microsoft.com/en-us/library/office/cc842512.aspx
3) It does kind of sound like a better way to solve this would be an Office.js function that gives write access to this? (though we don't completely understand your scenario). Request for new features should go through UserVoice:
https://officespdev.uservoice.com/forums/224641-general/category/131778-outlook-add-ins.
4) Being in Online Mode would greatly mitigate the time. A User can know whether or not he or she is in online mode, but an Add-in cannot.
https://support.office.com/en-us/article/Turn-on-Cached-Exchange-Mode-7885af08-9a60-4ec3-850a-e221c1ed0c1c
Additionally, the status bar will say "Connected to Microsoft Exchange" in cached mode, and "Online with Microsoft Exchange" in online mode.
Switching to Online mode, removes a lot of the benefits that cached mode has. Cached mode is default in Outlook 2016.

How to listen an MailItem event in Mail Add-in?

I want to detect an event in Mail Add-in. In Outlook, thick/desktop version, we can detect the mail event, such as MailItem.Send and MailItem.AttachmentAdd.
Is it possible to listen to these events in Outlook online?
Unfortunately there are almost no events of any kind in the Mailbox API, other than asynchronous callbacks that are only fired when you initiate them. There is nothing that I'm aware of that can be used to detect item send or attachment modification events.
The closest option is to use the Outlook Notifications REST API (https://msdn.microsoft.com/office/office365/APi/notify-rest-operations), but these are more suitable to monitoring item/folder level changes. Perhaps you can hook into a notification for the Sent Items folder to approximate a MailItem.Send operation, or watch changes to a draft item to detect a newly added attachment.
nop. you can't do this. Office Apps can't interact with buttons or actions on the client apps such as: Outlook.

Resources