none
How to update the Body of Office365 Mail with Javascript API RRS feed

  • Question

  • To my understanding, I cannot use the javascript api to update the body of an email or calendar.

    If I have that wrong, could you share a link that shows me the objects I would use or sample code on how to do so with JavaScript?

    thanks.

    Thursday, June 12, 2014 8:06 PM

Answers

  • Hi,

    Thank you for posting in MSDN forum.

    At present, you could use Office.context.mailbox.item.body to get and set the body of a message or an appointment.

    Please take a look at the sample from Item object (JavaScript API for Office v1.1) to get an item.

    // The initialize function is required for all apps.
    Office.initialize = function () {
        // Checks for the DOM to load using the jQuery ready function.
        $(document).ready(function () {
        // After the DOM is loaded, app-specific code can run.
        var item = Office.context.mailbox.item;
        var subject = item.subject;
        // Continue with processing the subject of the current item, which can be a message or appointment.
        });
    }
    

    Related articles for your reference:

    Message object (JavaScript API for Office v1.1)

    Appointment object (JavaScript API for Office v1.1)

    Hope this helps.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 16, 2014 1:34 AM
    Moderator
  • Hi Jmennear,

    There are a few ways you can update the body of a message or appointment.

    If your scenario requires your mail app to be activated in a compose form, you can use the following methods:

    Your mail app would need to specify ReadWriteItem permission in the manifest. Please see How to: Insert data in the body when composing an appointment or message in Outlook for how to use them.

    Alternatively, you can use Mailbox.makeEwsRequestAsync  and the Exchange Web Services (EWS) UpdateItem operation. In this case, your mail app can be activated in a read or compose form, and would need to specify the highest ReadWriteMailbox permission. See Call web services from a mail app for Outlook for more information.

    Allow me to clarify one point: if you need to get the body of a message or appointment, you cannot use the Body object. The Body object exposes only a getTypeAsync method to get the body type, not a get method to get the actual body. However, if you app activates in a read form and requests ReadItem permission, you can use the following API:

    • Mailbox.getCallbackTokenAsync to get a callback token
    • Mailbox.ewsUrl to get the Exchange server end point for the user's mailbox  
    • Item.itemId to get the item ID of the item of interest

    and pass these to your mail app's server-side code which can then call the EWS GetItem operation to get the entire item including the item body.

    You can read more about getting the entire item including the body here. This process is similar to getting attachments using a callback token and the EWS GetAttachments operation, for which there is an example.

    Hope this helps.

    Angelgolfer

    Wednesday, June 18, 2014 12:12 AM
    Answerer

All replies

  • Hi,

    Thank you for posting in MSDN forum.

    At present, you could use Office.context.mailbox.item.body to get and set the body of a message or an appointment.

    Please take a look at the sample from Item object (JavaScript API for Office v1.1) to get an item.

    // The initialize function is required for all apps.
    Office.initialize = function () {
        // Checks for the DOM to load using the jQuery ready function.
        $(document).ready(function () {
        // After the DOM is loaded, app-specific code can run.
        var item = Office.context.mailbox.item;
        var subject = item.subject;
        // Continue with processing the subject of the current item, which can be a message or appointment.
        });
    }
    

    Related articles for your reference:

    Message object (JavaScript API for Office v1.1)

    Appointment object (JavaScript API for Office v1.1)

    Hope this helps.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 16, 2014 1:34 AM
    Moderator
  • Hi Jmennear,

    There are a few ways you can update the body of a message or appointment.

    If your scenario requires your mail app to be activated in a compose form, you can use the following methods:

    Your mail app would need to specify ReadWriteItem permission in the manifest. Please see How to: Insert data in the body when composing an appointment or message in Outlook for how to use them.

    Alternatively, you can use Mailbox.makeEwsRequestAsync  and the Exchange Web Services (EWS) UpdateItem operation. In this case, your mail app can be activated in a read or compose form, and would need to specify the highest ReadWriteMailbox permission. See Call web services from a mail app for Outlook for more information.

    Allow me to clarify one point: if you need to get the body of a message or appointment, you cannot use the Body object. The Body object exposes only a getTypeAsync method to get the body type, not a get method to get the actual body. However, if you app activates in a read form and requests ReadItem permission, you can use the following API:

    • Mailbox.getCallbackTokenAsync to get a callback token
    • Mailbox.ewsUrl to get the Exchange server end point for the user's mailbox  
    • Item.itemId to get the item ID of the item of interest

    and pass these to your mail app's server-side code which can then call the EWS GetItem operation to get the entire item including the item body.

    You can read more about getting the entire item including the body here. This process is similar to getting attachments using a callback token and the EWS GetAttachments operation, for which there is an example.

    Hope this helps.

    Angelgolfer

    Wednesday, June 18, 2014 12:12 AM
    Answerer