Я создал свой первый Outlook.web.addin, используя office.js,
Но мне нужен способ отправить предопределенную почту определенному получателю, не показывая пользователю экран «создание сообщения»...
Ниже код открывает экран создания, но я не могу отправить, не заставляя пользователя нажать кнопку отправки.
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: ['[email protected]'],
ccRecipients: ['[email protected]'],
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(["[email protected]"]);
newItem.body.setAsync(["This is a test message"]);
newItem.addItemAttachmentAsync(
itemId,
"Welcome email"
);
newItem.saveAsync(
function callback(result) {
alert(result);
});
} else {
return;
}
}
Я ожидаю отправить сообщение, не позволяя пользователю изменять какие-либо детали в сообщении.





Вы можете добиться чего-то подобного, отправив запрос СоздатьЭлемент EWS с помощью СделатьEWSREquestAsync. В приведенном ниже примере будет отправлено электронное письмо самому себе, но вы можете изменить его по своему усмотрению.
var request = '<soap:Envelope xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:m = "http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t = "http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap = "http://schemas.xmlsoap.org/soap/envelope/">'+
' <soap:Header><t:RequestServerVersion Version = "Exchange2010" /></soap:Header>'+
' <soap:Body>'+
' <m:CreateItem MessageDisposition = "SendAndSaveCopy">'+
' <m:SavedItemFolderId><t:DistinguishedFolderId Id = "sentitems" /></m:SavedItemFolderId>'+
' <m:Items>'+
' <t:Message>'+
' <t:Subject>Hello, Outlook!</t:Subject>'+
' <t:Body BodyType = "HTML">Hello World!</t:Body>'+
' <t:ToRecipients>'+
' <t:Mailbox><t:EmailAddress>' + Office.context.mailbox.userProfile.emailAddress + '</t:EmailAddress></t:Mailbox>'+
' </t:ToRecipients>'+
' </t:Message>'+
' </m:Items>'+
' </m:CreateItem>'+
' </soap:Body>'+
'</soap:Envelope>';
Office.context.mailbox.makeEwsRequestAsync(request, function (asyncResult) {
if (asyncResult.status == "failed") {
showMessage("Action failed with error: " + asyncResult.error.message);
}
else {
showMessage("Message sent!");
}
});Я не уверен, вам придется искать информацию о EWS, чтобы увидеть, что возможно. У вас есть текущий элемент itemId из Office.JS.
Спасибо, это сработало волшебным образом, но как я могу отправить текущее электронное письмо в виде вложения?