Office Add-in Outlook API attach document using displayNewMessageForm method issue

依然范特西╮ 提交于 2019-12-22 00:08:30

问题


I'm working on office Add-in for Outlook. Need to open a new message with a pre-defined attachment.

Trying to get an attachment from the current item (message) as below:

 Office.context.mailbox.item.attachments

Here is an output (i get attachment type, id, size and so on):

Then I'm trying to attach this file to a new message in Outlook via add-in outlook API, here is an example from Office Developer that I use to attach the file I just get from the other email (like 'forward' functionality):

  Office.context.mailbox.displayNewMessageForm(
  {
    toRecipients: Office.context.mailbox.item.to, // Copy the To line from current item
    ccRecipients: ['sam@contoso.com'],
    subject: 'Outlook add-ins are cool!',
    htmlBody: 'Hello <b>World</b>!<br/><img src="cid:image.png"></i>',
    attachments: [
      {
        type: 'file',
        name: 'image.png',
        url: 'http://contoso.com/image.png',
        isInline: true
      }
    ]
  });

Here is an issue: I'm getting an exception 'Value doesn't fall within the expected range'. Parameter name: Attachments.

Help is really appreciated.


回答1:


According to documentation on displayNewMessageForm there are currently two attachment types are supported. To attach file to the item the attachment object should looks like ...

{
    type: 'file',
    name: 'image.png',
    url: 'http://contoso.com/image.png',
    isInline: true
}

To attach the item from existing message the object should looks ...

{
    type: 'item',
    name: 'image.png',
    itemId: 'ews_item_id_goes_here'
}


来源:https://stackoverflow.com/questions/50686499/office-add-in-outlook-api-attach-document-using-displaynewmessageform-method-iss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!