【发布时间】:2019-03-22 06:29:18
【问题描述】:
我创建了一个附加电子邮件的 EWS 请求,但我从中收到空值,但状态为“成功”。 顺便说一句。
我首先创建了一个将电子邮件保存到草稿的 makeEwsRequestAsync 请求,它已经可以使用,但是当我尝试使用此请求向它添加附件时,它没有添加。任何建议或帮助请
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
function createAttachment() {
var request =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <soap:Body>' +
' <CreateAttachment xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <ParentItemId Id="'+itemID+'" />' +
' <Attachments>' +
' <t:ItemAttachment>' +
' <t:Name>Please</t:Name>' +
' <t:Message>' +
' <t:ItemClass>IPM>Note</t:ItemClass>' +
' <t:Subject>test</t:Subject>' +
' <t:Body BodyType="Text">my test</t:Body>' +
' </t:Message>' +
' </t:ItemAttachment>' +
' </Attachments>' +
' </CreateAttachment>' +
' </soap:Body>' +
'</soap:Envelope>';
return request;
}
</script>
这是我的创建附件 EWS 请求
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
function composeMail(emailSubject, emailDescription) {
var subject= subjectPrefix + " " + emailSubject;
var request =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
' 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>' +
' <RequestServerVersion Version="Exchange2007_SP1" />' +
' </soap:Header>' +
' <soap:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
' <m:CreateItem MessageDisposition="SaveOnly">' +
' <m:SavedItemFolderId>' +
' <t:DistinguishedFolderId Id="drafts" />' +
' </m:SavedItemFolderId>' +
' <m:Items>' +
' <t:Message>' +
' <t:ItemClass>IPM.Note</t:ItemClass>' +
' <t:Subject>' + subject + '</t:Subject>' +
' <t:Body BodyType="HTML">' + emailDescription + '</t:Body>' +
' <t:Importance>Low</t:Importance>' +
' <t:ToRecipients>' +
' <t:Mailbox>' +
' <t:EmailAddress>' + recepient + '</t:EmailAddress>' +
' </t:Mailbox>' +
' </t:ToRecipients>' +
' <t:IsRead>false</t:IsRead>' +
' </t:Message>' +
' </m:Items>' +
' </m:CreateItem>' +
' </soap:Body>' +
'</soap:Envelope>';
return request;
}
</script>
这是我的创建电子邮件 EWS 请求
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
function send() {
var request =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <soap:Body>' +
' <SendItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"' +
' SaveItemToFolder="true">' +
' <ItemIds>' +
' <t:ItemId Id="' + itemID + '"/>' +
' </ItemIds>' +
' </SendItem>' +
' </soap:Body>' +
'</soap:Envelope>';
return request;
}
</script>
这是我发送 EWS 请求,我正在使用
呼叫他们<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
function sendRequest(emailSubject, emailDescription, emailItemID) {
// Create a local variable that contains the mailbox.
try {
itemID = Office.context.mailbox.item.itemId;
Office.context.mailbox.makeEwsRequestAsync(
composeMail(emailSubject, emailDescription), callbackCompose);
Office.context.mailbox.makeEwsRequestAsync(
createAttachment(), callbackAttachment);
Office.context.mailbox.makeEwsRequestAsync(
send(), callbackSend);
} catch (error) {
$("#id-error-msg").text(error);
}
</script>
【问题讨论】:
-
您能否使用附件 API 创建附件而不是 makeEwsRequest? addFileAttachmentAsync。您使用 makeEwsRequest 是否有特殊原因?
-
即使在电子邮件的阅读模式下我也需要发送电子邮件,但根据我已阅读和尝试的内容,addFileAttachmentAsync 仅在用户处于撰写模式时才有效。所以我切换到 EWS 请求。请让我知道它是否可能。提前致谢!
-
makeEwsRequestAsync 中支持的方法是有限的。见docs.microsoft.com/en-us/outlook/add-ins/web-services。特别是,通过 makeEwsRequestAsync 不支持 CreateAttachment。要发送新电子邮件,您是否考虑过使用图形 API? docs.microsoft.com/en-us/outlook/add-ins/use-rest-api
-
感谢您的及时回复:)。顺便提一句。我能够让它工作,但需要我修改很多。首先,我删除了 2 个 EWS 请求(发送和创建附件),然后我在创建项目请求中使用 Mime 添加了附件。我可以使用对 Exchange Server 的请求来获取 MimeContent。
-
另外,关于图形 API。我尝试使用 restUrl 但不知何故它在 Outlook for desktop 中返回 undefined 但在 Outlook web 中工作正常。谢谢!
标签: outlook exchangewebservices outlook-addin office-js add-in