如何在新电子邮件中写入提取的电子邮件标题



我正在尝试开发一个Outlook加载项,该加载项允许从选定的电子邮件中提取标题并将其打印到新的电子邮件中。

为此,我使用以下方法创建了一封新的电子邮件,其中包括所选电子邮件作为附件:

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

我查看了以下方法来从所选电子邮件中获取标题:

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

(Un(幸运的是,这个方法是异步的,我在创建新的电子邮件(displayNewMessageForm(后得到标题。我的目标是在用于创建新电子邮件的参数htmlBody中写入这些标题。

我尝试使用异步方法创建电子邮件(displayNewMessageFormAsync(,但没有成功。如果可能的话,我想(异步(获取邮件头,并将其作为displayNewMessageForm((方法的参数传递,或者更新创建的电子邮件以添加邮件头(如果可能,再次(。

我在寻求你的帮助!

应在getAllInternetHeadersAsync的回调处理程序中使用

displayNewMessageForm

这对我们有效:

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

最新更新