Office Add-in Outlook API attach document using di

2019-04-13 15:46发布

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):

enter image description here

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.

enter image description here

Help is really appreciated.

1条回答
闹够了就滚
2楼-- · 2019-04-13 16:18

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'
}
查看更多
登录 后发表回答