I had similar problem with getAttachmentContentAsync...
Try to use Promise.all - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
I have a function witch returns promises like this (to read attachments content):
return new Promise<any>((resolve, reject) => {
try {
const item = Office.context.mailbox.item;
if (item.attachments.length > 0) {
const promises: any[] = [];
for (let i: number = 0; i < item.attachments.length; i++) {
promises.push(
new Promise<any>((resolve2, reject2) => {
item.getAttachmentContentAsync(
item.attachments[i].id,
{ asyncContext: item.attachments[i] },
(result: Office.AsyncResult<Office.AttachmentContent>) => {
if (result.status === Office.AsyncResultStatus.Succeeded) {
switch (result.value.format) {
case Office.MailboxEnums.AttachmentContentFormat.Base64:
// Handle file attachment.
resolve2({
attachmentsDetails: result.asyncContext,
attachmentsContent: {
type: Office.MailboxEnums.AttachmentContentFormat.Base64,
content: this.getBinaryFileContents(result.value.content),
},
});
break;
case Office.MailboxEnums.AttachmentContentFormat.Eml:
// Handle email item attachment.
resolve2({
attachmentsDetails: result.asyncContext,
attachmentsContent: {
type: Office.MailboxEnums.AttachmentContentFormat.Eml,
content: 'email',
},
});
break;
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
// Handle .icalender attachment.
resolve2({
attachmentsDetails: result.asyncContext,
attachmentsContent: {
type: Office.MailboxEnums.AttachmentContentFormat.Eml,
content: 'icalender',
},
});
break;
case Office.MailboxEnums.AttachmentContentFormat.Url:
// Handle cloud attachment.
resolve2({
attachmentsDetails: result.asyncContext,
attachmentsContent: {
type: Office.MailboxEnums.AttachmentContentFormat.Url,
content: 'URL',
},
});
break;
default:
resolve2({
attachmentsDetails: result.asyncContext,
attachmentsContent: undefined,
});
break;
}
} else {
reject2({
data: undefined,
error: result.error.message,
});
}
},
);
}),
);
}
Promise.all(promises)
.then((results) => {
console.log(results);
resolve({
data: results,
error: '',
});
})
.catch((e) => {
reject({
data: undefined,
error: e,
});
});
} else {
resolve({
data: [],
error: '',
});
}
} catch (error) {
reject({
data: undefined,
error: error,
});
}
});