我想在发送电子邮件时显示警告消息。并且只有在用户点击关闭后发送。我在notificationMessages上将持久化设置为true。但是在发送电子邮件时,邮件会很快显示,但电子邮件会立即发送,而我没有机会阅读邮件。
知道我该怎么办?
Office.context.mailbox.item.notificationMessages.addAsync("cost_warning", {
type: "informationalMessage",
message: "message",
icon : "iconid",
persistent: true
});
event.completed({ allowEvent: true });
你可以通过使用NotificationMessage.getAllAsync API实现这一目标。
只需使用setInterval设置间隔并等到notificationMessage.getAllAsync()停止返回您的通知,然后调用event.completed({ allowEvent: true });
但我建议您使用dialog API并显示包含必要信息的网页,而不是使用通知消息。
通知消息不适用于阻止信息,对话框在此方案中更合适。
编辑:
// Add your notification message
var interval = window.setInterval(checkNotificationMessages, 2000);
function checkNotificationMessages() {
Office.context.mailbox.item.notificationMessages.getAllAsync(
function (asyncResult) {
if (asyncResult.status != "failed") {
if (asyncResult.value.length == 0 ) {
window.clearInterval(interval);
// Perform some action and decide whether to allow/block send
}
}
}
);
}