【发布时间】:2019-07-25 00:53:41
【问题描述】:
我使用 office.js 构建了我的第一个 Outlook.web.addin,
但我需要一种方法来向某个收件人发送预定义的邮件,而不向用户显示“邮件撰写”屏幕...
下面的代码会打开撰写屏幕,但如果不强制用户按下发送按钮,我就无法发送。
function sendMessage() {
if (Office.context.mailbox.item.itemType === Office.MailboxEnums.ItemType.Message) {
var mailbox = Office.context.mailbox;
var item = mailbox.item;
var itemId = item.itemId;
if (itemId === null || itemId == undefined) {
item.saveAsync(function(result) {
itemId = result.value;
});
}
Office.context.mailbox.displayNewMessageForm(
{
// Copy the To line from current item.
toRecipients: ['xxx@xxx.net'],
ccRecipients: ['yyy@yyyy.com'],
subject: 'Outlook add-ins are cool!',
htmlBody: 'Hello <b>World</b>!<br/><img src="cid:image.png"></i>',
attachments: [
{
type: 'item',
name: 'Suspected phishing mail',
itemId: itemId
}
]
});
} else {
return;
}
}
我需要将上面的代码修改为:
function sendMessage() {
if (Office.context.mailbox.item.itemType === Office.MailboxEnums.ItemType.Message) {
var mailbox = Office.context.mailbox;
var item = mailbox.item;
var itemId = item.itemId;
if (itemId === null || itemId == undefined) {
item.saveAsync(function(result) {
itemId = result.value;
});
}
var newItem = mailbox.item;
newItem.to.setAsync(["xxx@xxx.net"]);
newItem.body.setAsync(["This is a test message"]);
newItem.addItemAttachmentAsync(
itemId,
"Welcome email"
);
newItem.saveAsync(
function callback(result) {
alert(result);
});
} else {
return;
}
}
我希望在发送消息时不允许用户更改消息中的任何细节。
【问题讨论】:
标签: office365 office-js office-addins outlook-web-addins