Failed to get the ItemAttachment
Uoliver opened this issue · 7 comments
when i used below code to load the attachment(it is a .msg attachment, in EWS is an ItemAttachment not FileAttachment) , an error occurred, error information:The element at position 0 is invalid. maybe is a bug to process the ItemAttachment, may you help ? thanks in advance.
below is the related code:
email.Load(new ews.PropertySet(ews.BasePropertySet.IdOnly, [ews.ItemSchema.Attachments, ews.ItemSchema.HasAttachments])).then(() => {
email.Attachments.Items.forEach(attach => {
console.log(attach.Items);
console.log('will load attach ' + attach.name + ' -----------------------------------');
attach.Load().then(() => {
console.log(attach.Base64Content);
}, error => {
console.log('Couldn't be loaded! ');
console.log(JSON.stringify(Object.keys(attach)));
});
}, (error) => {
if (error) {
console.log(error)
}
});
}, (error) => {
if (error) {
console.log(error)
}
});
Hi, first I would like to thank for your hard work on this library.
I am using 0.9.4 and I get this same error "The element at position 0 is invalid" when trying to do a .Load() on a attachment which is a email. I wonder if you have some pointers when working with ItemAttachments ?
Same here.
It only happens if the attachment is an Outlook Item, e.g., a link to another email. As @cm253 said here, to replicate it you have to drag and drop some email from your Inbox to your new message using Outlook (desktop or web).
I'm using: "ews-javascript-api": "^0.10.3"
Stack trace:
// error.message
TypeError: Cannot read property 'Attachments' of null
at ItemAttachment.Validate (node_modules/ews-javascript-api/js/ComplexProperties/ItemAttachment.js:139:19)
at Function.EwsUtilities.ValidateParamAllowNull (node_modules/ews-javascript-api/js/Core/EwsUtilities.js:583:30)
at Function.EwsUtilities.ValidateParam (node_modules/ews-javascript-api/js/Core/EwsUtilities.js:570:14)
at Function.EwsUtilities.ValidateParamCollection (node_modules/ews-javascript-api/js/Core/EwsUtilities.js:608:22)
at GetAttachmentRequest.Validate (node_modules/ews-javascript-api/js/Core/Requests/GetAttachmentRequest.js:157:41)
at GetAttachmentRequest.ServiceRequestBase.ValidateAndEmitRequest (node_modules/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js:394:14)
at node_modules/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js:55:19
at Promise._execute (node_modules/bluebird/js/release/debuggability.js:384:9)
at Promise._resolveFromExecutor (node_modules/bluebird/js/release/promise.js:518:18)
at new Promise (node_modules/bluebird/js/release/promise.js:103:10)
at GetAttachmentRequest.SimpleServiceRequestBase.InternalExecute (node_modules/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js:52:16)
at node_modules/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js:48:19
at Promise._execute (node_modules/bluebird/js/release/debuggability.js:384:9)
at Promise._resolveFromExecutor (node_modules/bluebird/js/release/promise.js:518:18)
at new Promise (node_modules/bluebird/js/release/promise.js:103:10)
at GetAttachmentRequest.MultiResponseServiceRequest.Execute (node_modules/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js:47:16)
// error.InnerException.stack
Exception: Validation failed.
at Function.EwsUtilities.ValidateParamAllowNull (node_modules/ews-javascript-api/js/Core/EwsUtilities.js:586:23)
at Function.EwsUtilities.ValidateParam (node_modules/ews-javascript-api/js/Core/EwsUtilities.js:570:14)
at Function.EwsUtilities.ValidateParamCollection (node_modules/ews-javascript-api/js/Core/EwsUtilities.js:608:22)
at GetAttachmentRequest.Validate (node_modules/ews-javascript-api/js/Core/Requests/GetAttachmentRequest.js:157:41)
at GetAttachmentRequest.ServiceRequestBase.ValidateAndEmitRequest (node_modules/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js:394:14)
at node_modules/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js:55:19
at Promise._execute (node_modules/bluebird/js/release/debuggability.js:384:9)
at Promise._resolveFromExecutor (node_modules/bluebird/js/release/promise.js:518:18)
at new Promise (node_modules/bluebird/js/release/promise.js:103:10)
at GetAttachmentRequest.SimpleServiceRequestBase.InternalExecute (node_modules/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js:52:16)
at node_modules/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js:48:19
at Promise._execute (node_modules/bluebird/js/release/debuggability.js:384:9)
at Promise._resolveFromExecutor (node_modules/bluebird/js/release/promise.js:518:18)
at new Promise (node_modules/bluebird/js/release/promise.js:103:10)
at GetAttachmentRequest.MultiResponseServiceRequest.Execute (node_modules/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js:47:16)
at ExchangeService.InternalGetAttachments (node_modules/ews-javascript-api/js/Core/ExchangeService.js:1044:24)
Are you able to suggest changes in code?
Sorry for the delay in the reply. I'm unable to contribute because I have not ever use Typescript. But I'm sure the problem is that: when you drag and drop an email into another, you are creating a link not a copy of a real file (ItemAttachment instead of FileAttachment)... so ews-javascript-api crashes while it loads the attachment.
possible workaround for this: #389 (comment)