Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda