Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Extract mail body of outlook using javascript function

I am trying to get the body of my outlook mail using javascript. Currently i am able to extract title but not body.

document.getElementById("fill-data").onclick = function () {
        var item = Office.context.mailbox.item;
        var bodyContent;
        Office.context.mailbox.item.body.getAsync('text', function (async) {bodyContent = async.value});
        document.getElementById("txt-subject").value = item.subject;
       // The below code returns "undefined"
        document.getElementById("txt-description").value = bodyContent;  
    };

Office.context.mailbox.item.body.getAsync('text', function (async) {bodyContent = async.value}); is not returning body instead it returns "undefined" into my textbox .How can i extract body of outlook mail?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Office.context.mailbox.item.body.getAsync(
    'text', 
    function (async) {bodyContent = async.value}
);

sets the value of bodyContent in its callback. The callback is invoked asynchronously (i.e. the call to Office.context.mailbox.item.body.getAsync does not block).

This means that by the time you

document.getElementById("txt-description").value = bodyContent;

that callback function has not yet been invoked and bodyContent has not been assigned to

Don't set the value until the callback has been invoked. How? Just doing it in the callback would be one way.

Office.context.mailbox.item.body.getAsync(
    'text', 
    function (result) {
        document.getElementById("txt-description").value = result.value;
    }
);

Side-note: I'd strongly recommend against the variable-name async, even if your environment allows it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!