Outlook Web Add-in邮件转附件功能故障排查求助
问题描述
我的Outlook Web加载项无法正常运行,执行到// Get the selected email message步骤后无任何响应。控制台报错:Uncaught (in promise) SyntaxError: Unexpected token 'H', "HTTP/1.1 4"... is not valid JSON。
需实现的功能:用户输入一个数字作为新邮件的主题,将选中的邮件作为附件发送至recipient@recipient.com。相关代码如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Ask Dossiernr</title> <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script> <!-- Office UI Fabric CSS --> <link rel="stylesheet" href=https://appsforoffice.microsoft.com/fabric/2.1.0/fabric.min.css /> <link rel="stylesheet" href=https://appsforoffice.microsoft.com/fabric/2.1.0/fabric.components.min.css /> </head> <body> <div class="ms-welcome"> <form id="emailForm"> <p class="ms-fontSize-l ms-fontWeight-light ms-fontColor-neutralPrimary">Vul het dossiernummer in en klik op de knop om te versturen. V1.8</p> <br /> <input type="text" id="dossierNr" class="ms-TextField-field" value="1234567"> <br /><br /> <button id="verzenden" class="ms-Button ms-Button--primary"> <span class="ms-Button-label">Versturen</span> </button> </form> </div> <script> (function () { Office.initialize = function (reason) {}; // Add click event listener to the "Versturen" button document.getElementById("verzenden").addEventListener("click", function () { var dossierNr = document.getElementById("dossierNr").value; console.log(dossierNr); console.log("clicked"); // Get the selected email message Office.context.mailbox.item.getSelectedDataAsync( Office.CoercionType.Html, function (asyncResult) { console.log("getSelectedDataAsync callback called"); console.log(asyncResult); if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { // Create a new email message with the selected email as an attachment var newEmail = Office.context.mailbox.item.createReplyAll(); newEmail.to.setAsync(["receiver@receiver.com"]); // Add recipient newEmail.subject = dossierNr; newEmail.body.setSelectedDataAsync( asyncResult.value, { coercionType: Office.CoercionType.Html }, function (asyncResult) { if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { // Add the selected email as an attachment var attachment = { type: Office.MailboxEnums.AttachmentType.Item, itemId: Office.context.mailbox.item.itemId, name: "Original Email", }; newEmail.addFileAttachmentAsync( attachment.itemId, attachment.name, { asyncContext: attachment }, function (asyncResult) { if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { // Send the new email newEmail.send(); } else { console.error("Error adding attachment: " + asyncResult.error.message); } } ); } else { console.error("Error setting email body: " + asyncResult.error.message); } } ); } else { console.error("Error getting selected email: " + asyncResult.error.message); } } ); }); })(); </script> </body> </html>
内容的提问来源于stack exchange,提问作者Crikkelieke
相关产品推荐
相关产品推荐

