1
votes

Following the documentation here https://docs.microsoft.com/en-us/office/dev/add-ins/reference/objectmodel/requirement-set-1.7/office.context.mailbox.item#attachments-arrayattachmentdetailsjavascriptapioutlook17officeattachmentdetails

When I try to access the attachments as per the documentation:

var _Item = Office.context.mailbox.item;
var outputString = "";

if (_Item.attachments.length > 0) {
  for (i = 0 ; i < _Item.attachments.length ; i++) {
    var _att = _Item.attachments[i];
    outputString += "<BR>" + i + ". Name: ";
    outputString += _att.name;
    outputString += "<BR>ID: " + _att.id;
    outputString += "<BR>contentType: " + _att.contentType;
    outputString += "<BR>size: " + _att.size;
    outputString += "<BR>attachmentType: " + _att.attachmentType;
    outputString += "<BR>isInline: " + _att.isInline;
  }
}

// Do something with outputString

the returned value is undefined.

Output from running the code sample from the docs

The attached file is not of a type on the blocked attachments type list linked in that documentation page.

Please help me understand what I'm doing wrong. The code is being called from an existing 365 add-in that is currently available on the 365 store, from a file where we access the Office 365 Javascript API. The call that I made in the provided screenshot happens directly after we successfully retrieve the 'to', 'cc', and 'bcc' values for the same email item, using the same JS API method Office.context.mailbox.item

1
Is the message in Read mode or Compose mode (i.e. a received message or a draft)? And does this happen with all attachments or just for a particular attachment? - Outlook Add-ins Team - MSFT
This happens in compose mode, with all attachments that I've tried so far. - evanchurchill
Just realized after answering your question that it is only available in the "Read" context, as per the docs. Thanks! Is there a way to get attachments from the "compose" context, without hitting the REST API? - evanchurchill

1 Answers

2
votes

RTFM - the method is only available in the "Read" context, not in the "Compose" context.