Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda