繁体   English   中英

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

[英]Attach selected email as an attachment to a draft email

我正在尝试使用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() ,其中 item 是get-a-message api 的响应,但由于item.addItemAttachmentAsync is not a function而出错

我觉得我在这里做错了任何人都可以帮忙。

编辑:

我觉得我的问题有些混乱,所以让我添加更多上下文。 我的加载项在收件箱电子邮件项上运行,因此当用户单击加载项时,我希望将电子邮件Office.context.mailbox.item作为附件转发到某个电子邮件地址,包括Office.context.mailbox.item附件和电子邮件标题。 这可以使用 SOAP api 使用这样的东西

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

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

要将项目添加为附件,您应该使用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);
        }
    }
});

您还可以根据上述请求中的场景添加 to/cc 收件人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM