Reputation: 75
Hi how can i get attachments and send it to my java server?
in docs its say:
var item = Office.context.mailbox.item;
var options = {asyncContext: {currentItem: item}};
item.getAttachmentsAsync(options, callback);
function callback(result) {
if (result.value.length > 0) {
for (i = 0 ; i < result.value.length ; i++) {
result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
}
}
}
function handleAttachmentsCallback(result) {
// Parse string to be a url, an .eml file, a base64-encoded string, or an .icalendar file.
switch (result.value.format) {
case Office.MailboxEnums.AttachmentContentFormat.Base64:
// Handle file attachment.
break;
case Office.MailboxEnums.AttachmentContentFormat.Eml:
// Handle email item attachment.
break;
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
// Handle .icalender attachment.
break;
case Office.MailboxEnums.AttachmentContentFormat.Url:
// Handle cloud attachment.
break;
default:
// Handle attachment formats that are not supported.
}
}
But i have several errors witch this example.
first is item.getAttachmentsAsync is not a function
then im tried to use
result.asyncContext.currentItem.getAttachmentContentAsync(item.attachments[2].id, handleAttachmentsCallback);
but its never called calback
How can i get attachments and send them by XMLHttpRequest to my server?
Upvotes: 0
Views: 1806
Reputation:
However, as mentioned in Jadams answer, getAttachmentContentAsync IS supported in Read Mode, and you can get that to the the Base64 encoding of attachments. (the first link will be updated soon to reflect this)
Upvotes: 1
Reputation: 185
Most likely what is happening is that you are trying this code on a read item. The getAttachmentsAsync
fn only exists in compose mode, so you would see the error above if you are not composing an email. For read emails you should be able to just access the attachments property Office.context.mailbox.item.attachments
(https://learn.microsoft.com/en-us/javascript/api/outlook/office.attachmentdetails?view=outlook-js-preview)
Upvotes: 0