In this article I will demonstrate the simple getter and setter methods for getting the subject from an Outlook email, changing it and updating it.
Introduction
A customer came to us with the request to be able to push a button in outlook and set distinct values into the subject line of an email. The reason for wanting to do it this was way to ensure that there was no spelling issues and or other potential mistakes. The information in the subject can then be parsed and acted on as it passes through the email transport process.
Getting and Setting the subject
Looking at the dev.outlook.com documentation for Add-Ins we can see that there are two Async methods for getting and setting the subject from an email.
getAsync(options, callback) setAsync(subject, options, callback)
in both cases the options variable is able to pass information into the Async function so it can be executed on after at the time the callback is executed. In this case we will not be using them.
To demonstrate the capability I used my Firebug lite console within both the outlook and owa clients to get the subject, add a message to it and then set the subject. This gives the overall impression to the user that you are “inserting” the information into the email subject.
Office.context.mailbox.item.subject.getAsync( {}, function(res){ var subject = res.value Office.context.mailbox.item.subject.setAsync( '[RANDOMTEXTHERE] '+subject {}, function(){ }) })
In Outlook
and in OWA
This simple functionality can be added into a button within the Ribbon bar and you have the desired Add-In for the customer.
Conclusion
In this article we have seen that getting and setting the Subject of an email in Outlook/OWA is very simple and easy to run within the client/browser