Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

office js - How to write extracted email headers in a new email

I'm trying to develop an Outlook Add-In that allows to extract headers from a selected email and print them in a new email.

For that need, I used the following method to create a new email that includes, as an attachment, the selected email:

Office.context.mailbox.displayNewMessageForm({
    toRecipients: ["[email protected]"],
    subject: mailSubject,
    htmlBody: mailBody,
    attachments: [{ type: "item", itemId: Office.context.mailbox.item.itemId, name: Office.context.mailbox.item.subject }]
});

I looked at the following method to get the headers from the selected email:

Office.context.mailbox.item.getAllInternetHeadersAsync(
    function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
            headers = asyncResult.value; // get the headers
        }
    }
);

(Un)fortunately, this method is asynchronous and I get the headers after the creation of the new email (displayNewMessageForm). My goal is to write these headers in the parameter htmlBody used for the creation of the new email.

I tried to used the async method for the email creation (displayNewMessageFormAsync), without success. If possible, I want to get the headers (asynchronously) and pass them as a parameter of the displayNewMessageForm() method or update the created email to add the headers (if possible again).

I'm looking for your help!

question from:https://stackoverflow.com/questions/65626223/how-to-write-extracted-email-headers-in-a-new-email

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

displayNewMessageForm should be used in the callback handler of getAllInternetHeadersAsync.

This works for us:

Office.context.mailbox.item.getAllInternetHeadersAsync(
    function(asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
            headers = asyncResult.value; // get the headers
            Office.context.mailbox.displayNewMessageForm({
                toRecipients: ["[email protected]"],
                subject: "Test Subject",
                htmlBody: "Internet headers: " + headers,
                attachments: [{
                    type: "item",
                    itemId: Office.context.mailbox.item.itemId,
                    name: Office.context.mailbox.item.subject
                }]
            });
        }
    }
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...