I'm trying to send an email using the Outlook's office.js API's item.sendAsync() method which triggers on custom send button added on taskpane from a task pane add-in. However, I'm getting a Host Error with the following response:
{
"code": 5000,
"message": "The operation is not supported.",
"name": "Host Error"
}
Here is the code snippet I am using
item.sendAsync((result) => {
if (result.status === Office.AsyncResultStatus.Succeeded) {
document.getElementById('review-message').innerHTML =
'<p class="ms-font-xs" style="color: green;">✅ Email sent successfully via sendAsync!</p>';
// Close task pane after short delay
setTimeout(() => {
if (window.close) {
window.close();
}
}, 2000);
} else {
console.error('sendAsync failed:', result.error);
const error = result.error;
}
});
I am using it on Outlook for Mac (version 16.102)
Also I have added below permission in mainfest.xml
<Permissions>ReadWriteMailbox</Permissions>
I want to acheive below functionality in my addIn
- Display email data on taskpane also having custom send button
- send from custom send button available in taskpane (so above code snippet is triggered on button click)
sendAsync()probably causing this error because you are triggering this function on a button in UI, whilesendAsync()method only works in compose mode and can only be triggered UI-less command function (from the ribbon) although it cannot be called from the UI.