最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

office js - Need a sample for using displayNewMessageForm and addFileAttachmentFromBase64 together - Stack Overflow

programmeradmin0浏览0评论

I'm writing an outlook add-in and need to create a new email with displayNewMessageForm and add an attachment. The problem is the URL to the attachment is protected so I need to download the file and attach it and I've tried using addFileAttachmentFromBase64Async as shown in this example:

The problem I'm having is the very first line of the code sample:

const mailItem = Office.context.mailbox.item;

This gets the currently selected mailItem in the mailbox - not the new compose form that was displayed with displayNewMessageForm. Can someone provide a sample that uses displayNewMessageForm then using addFileAttachmentFromBase64Async attaches a file such as a word document to that new compose form?

I'm writing an outlook add-in and need to create a new email with displayNewMessageForm and add an attachment. The problem is the URL to the attachment is protected so I need to download the file and attach it and I've tried using addFileAttachmentFromBase64Async as shown in this example:

https://learn.microsoft/en-us/office/dev/add-ins/outlook/add-and-remove-attachments-to-an-item-in-a-compose-form#attach-a-file-or-outlook-item

The problem I'm having is the very first line of the code sample:

const mailItem = Office.context.mailbox.item;

This gets the currently selected mailItem in the mailbox - not the new compose form that was displayed with displayNewMessageForm. Can someone provide a sample that uses displayNewMessageForm then using addFileAttachmentFromBase64Async attaches a file such as a word document to that new compose form?

Share Improve this question asked Feb 1 at 22:10 S HuffS Huff 1162 silver badges11 bronze badges 5
  • I don't think so it is possible You can only attach attachments from url in displayNewMessageForm learn.microsoft/en-us/javascript/api/outlook/… – M Junaid Commented Feb 3 at 8:38
  • I know I can only attach from a URL in displayNewMessageForm but shouldn't I be able to attach to the new message from from addFielAttachmentFromBase64Async? – S Huff Commented Feb 3 at 13:22
  • You can attach when you are in compose Mode – M Junaid Commented Feb 7 at 7:22
  • I'm not sure what that means? When I open the new message with displayNewMessageForm - then shouldn't it be in "Compose Mode" how do I now get a hook into that to add the attachment? – S Huff Commented Feb 7 at 20:39
  • when you run displayNewMessageForm it's display a new message that's mean you are in compose mode now in compose mode you can add a button on your ribbon for adding attachments – M Junaid Commented Feb 8 at 6:14
Add a comment  | 

1 Answer 1

Reset to default 1 +50

You cannot insert attachments using addFileAttachmentFromBase64Async in Read Mode when using displayNewMessageForm.

To achieve this, you need to add attachments in Compose Mode.

After calling displayNewMessageForm, you are now in Compose Mode. You can add a new button in Compose Mode using MessageComposeCommandSurface for a Taskpane or an action button in your manifest.

      <ExtensionPoint xsi:type="MessageComposeCommandSurface">
          <OfficeTab id="TabDefault">
            <Group id="msgComposeGroup">
              <Label resid="GroupLabel"/>
              <Control xsi:type="Button" id="TaskpaneButton">
                <Label resid="TaskpaneButton.Label"/>
                <Supertip>
                  <Title resid="TaskpaneButton.Label"/>
                  <Description resid="TaskpaneButton.Tooltip"/>
                </Supertip>
                <Icon>
                  <bt:Image size="16" resid="Icon.16x16"/>
                  <bt:Image size="32" resid="Icon.32x32"/>
                  <bt:Image size="80" resid="Icon.80x80"/>
                </Icon>
                <Action xsi:type="ShowTaskpane">
                  <SourceLocation resid="Taskpane.Url"/>
                </Action>
              </Control>
            </Group>
          </OfficeTab>
        </ExtensionPoint>

Now here on Taskpane you can use the method of addFileAttachmentFromBase64Async for adding new attachments

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论