簡體   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