gautamsi / ews-javascript-api

EWS API for TypeScript/JavaScript - ported from OfficeDev/ews-managed-api - node, cordova, meteor, Ionic, Electron, Outlook Add-Ins
MIT License
281 stars 72 forks source link

Cannot get attachment of .EML type #434

Open german-st opened 5 months ago

german-st commented 5 months ago

Hello.

When reading emails with attachments in .EML format, we receive an error. Sorry in advance we can't use typescript. We use the version: 0.14.0 NodeJS version: v20.11.1

This comment does not work:

let items = await exch.FindItems(folderId, "isRead:false", view);
    for (var item of items.Items) {
        let res = await item.Load();
        let attachs = [];
    if (item.HasAttachments)
        {
        const exchangeAttachments = item.Attachments?.GetEnumerator() ?? [];
          for await (const attachment of exchangeAttachments) {
                const attachments = await exch.GetAttachments([attachment.Id], "HTML", []); //there's an error here
                console.log('attachments', attachments);
                const itemAttachment = attachments.Responses[0].Attachment;
                await itemAttachment.Load();
                console.log('attach', itemAttachment);
        }
    }

and getting error: image

If we try to simply download the attachment:

let items = await exch.FindItems(folderId, "isRead:false", view);
for (const item of items.Items) {
        let res = await item.Load();
    if (item.HasAttachments)
         {  
        for (const attach of item?.Attachments?.items) {
        console.log('attach', attach);
        let result = await attach.Load();  //there's an error here
         }
    }
}

and getting error: image

Or other variant:

for (const attach of item?.Attachments?.items) {
        console.log('attach', attach);
        let result = await attach.Load([attach.id]);  //there's an error here
        // }
}

and getting error: image

Maybe there is a solution to this problem? Thanks for the help.

peakala commented 3 months ago

Hi, I have a similar issue. I can get the ItemAttachment but its attribute "item" is empty, so I cannot retrieve anything of the eml attachment... but the name.

So no access to the body nor to the inner attachments. The method load on these attachments gives throw new ArgumentException_1.ArgumentException(ExtensionMethods_1.StringHelper.Format("The element at position {0} is invalid", count), paramName, e);

I am about to switch to python, a first prototype works...