将选定的电子邮件附加为草稿电子邮件的附件

问题描述 投票:0回答:1

我正在尝试使用create-an-item-attachment api添加一个电子邮件项目作为草稿电子邮件的附件,其中我提供的项目作为get-a-message api的响应,但我收到的错误如下:

@odata.id, @odata.context, @odata.etag
"The annotation 'odata.context' was found. This annotation is either not recognized or not expected at the current position."

如果我手动删除这两个注释,我会得到这些变量的错误。(我在给主题错误后停止了)

ReceivedDateTime, SentDateTime, HasAttachments, Subject

The property 'HasAttachments' does not exist on type 'Microsoft.OutlookServices.Item'. Make sure to only use property names that are defined by the type or mark the type as open type.

我确实看了看这个SO answer。但我不确定是否可以使用此方法向草稿电子邮件项添加附件。我试着调用item.addItemAttachmentAsync(),其中项目是get-a-message api的响应,但得到错误,因为item.addItemAttachmentAsync is not a function

我觉得我在做错事在这里任何人都可以提供帮助。

编辑:

我觉得我的问题有些混乱,所以让我添加更多背景。我的加载项在收件箱电子邮件项目上运行,因此当用户点击加载项时,我希望将电子邮件Office.context.mailbox.item转发到某个电子邮件地址作为附件,包括Office.context.mailbox.item附件和电子邮件标头。使用something like this的SOAP api可以实现这一点。

现在我正在使用Rest API,我无法完成使用SOAP api所做的事情,将邮件项目转发为带有电子邮件标题和原始电子邮件的附件。我正在使用/createforward创建一个新的草稿项目,然后尝试编辑草稿项目并附加/attachments

在这个SO post的帮助下,我能够将电子邮件作为附件发送。我最终从消息itemAttachment中删除了@odata.context,并将"@odata.type" : #Microsoft.OutlookServices.Message添加到消息itemAttachment中。但是现在附件中缺少附加的电子邮件标题。

office365 outlook-addin office-js outlook-restapi outlook-web-addins
1个回答
2
投票

要将项目添加为附件,您应该使用Office.js中的item.addFileAttachmentAsync()函数。

以下是如何执行此操作的示例:

// Example EWS Item ID
var itemId = "AAMkADU5ODYxOTI2LWQ5ODktNGNkMy05ZmU5LWY4ZWNlMmEwNDI4MwBGAAAAAAC8pAGEht5DRrHaTsDL/q5XBwCys1ms6AKZT7uAgKv13R58ABtsz8d7AABoPf5UVWMrTKxA5Yn7Am3VAAATUR7UAAA=";

Office.context.mailbox.item.addItemAttachmentAsync
(
    itemId,
    "message_name.msg",
    {
        // The values in asyncContext can be accessed in the callback
        "asyncContext" : { foo: 1, bar: 6, baz: true }
    },
    function (asyncResult)
    {
        showMessage(JSON.stringify(asyncResult));
    }
);

编辑:要将当前项目添加为新草稿消息的附件,您可以使用displayNewMessageFormAPI

Office.context.mailbox.displayNewMessageForm(
{
    htmlBody : "This is a sample with file and item attachments",
    attachments :
    [
        { type: "file", url: "http://i.imgur.com/9S36xvA.jpg", name: "dog.jpg" },
        { type: "item", itemId : Office.context.mailbox.item.itemId, name: "test_email.msg" }
    ],
    options : { asyncContext: null },
    callback : function (asyncResult)
    {
        if (asyncResult.status == "failed")
        {
            showMessage("Action failed with error: " + asyncResult.error.message);
        }
    }
});

您还可以根据上述请求中的方案添加到/ cc收件人。

© www.soinside.com 2019 - 2024. All rights reserved.