2
votes

I am planning to write an Outlook Add-in and I was wondering if there was a way to listen to events, such as the "send button". In practice, I'd like to manipulate the body when the user presses the send button and so, even before sending the email.

From what I have seen, the only way to do this, is to create a button, such as "manipulate", and attach an event on the on-click. It's feasible, but it's quite annoying if you have to do it every single time you send an email.

Further, how does Outlook run the add-ins? In compose mode, if I do have a:

Office.context.mailbox.item.body.getAsync

Is this run whenever I type a new letter in my body or when I send the message? I am a bit confused.

This could slightly be a duplicate. Thanks again.

2

2 Answers

2
votes

You cannot attach listeners on DOM elements of the parent window of your iFrame (where your add-in lives). So you cannot hack the behavior of Outlook Web Access buttons.

It is important to note that the new Office web addins generation are less intrusive than old desktop addins. Indeed, with VSTO for example, one does have access to the entire Outlook Object Model for better or for worse. Here is a blog post that I wrote on the subject.

The solution you describe seems the suitable way to do what you want. In addition, let me stress out that its a good thing that web addins framework do not let you change the content of an email without user consent.

Keep in mind that Office.js offers you the possibility to communicate with EWS API which is very useful when something is not available directly from the Office.js API. See this link.

1
votes

Regarding "Is this run whenever I type a new letter in my body or when I send the message?"

By my experimentation it will return the new body content every few seconds (close to ~20 seconds), even if you call Office.context.mailbox.item.body.getAsync every second.

I don't know why this interval of refresh exists, it's not documented AFAIK, and why it's not refreshed in every letter as happens in VSTO add-in.

The only (strange) method I found to get it refreshed in real time is if the user presses the task pane.

I guess we'll have to wait for something like excel js api events.