Outlook Web App(Exchange 2013内部部署)API 1.2如何访问电子邮件正文? [英] Outlook Web App (Exchange 2013 On-Premise) API 1.2 How to access Email Body?
问题描述
Office.context.mailbox.item.body
给出空值
Office.context.mailbox.item.body.getAsync()
仅适用于JavaScript API 1.3
.
是否可以使用JavaScript API 1.1/1.2
获取电子邮件正文?
Is there any way to fetch email body with JavaScript API 1.1/1.2
?
推荐答案
可以.实际上,您将使用Exchange Web服务检索正文.
Yes you can. Actually, you will retrieve the body using Exchange Web Services.
此处有两种方法可以做到这一点:1)来自javascript(客户端应用)的SOAP请求或2)使用SDK的服务器端(例如.NET Exchange Web SDK)
As explained here there are two ways to do this: 1) SOAP request from javascript (client app) or 2) server side using an SDK such as the .NET Exchange Web SDK
对于解决方案1),您的请求可能类似于以下js代码段(请注意,我在that.$q.defer();
中使用了angular.js诺言,但这不是强制性的)
For solution 1), your request could look like the following js snippet (note that I have used an angular.js promise with that.$q.defer();
but this is not mandatory)
function getSoapEnvelope(request) {
// Wrap an Exchange Web Services request in a SOAP envelope.
var result =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <soap:Header>' +
' <t:RequestServerVersion Version="Exchange2013"/>' +
' </soap:Header>' +
' <soap:Body>' +
request +
' </soap:Body>' +
'</soap:Envelope>';
return result;
}
var getBodyAsync = function () {
var that =this;
var deferred = that.$q.defer();
function getHeadersRequest(id) {
// Return a GetItem EWS operation request for the headers of the specified item.
var result =
' <GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +
' <ItemShape>' +
' <t:BaseShape>IdOnly</t:BaseShape>' +
' <t:BodyType>HTML</t:BodyType>' +
' <t:AdditionalProperties>' +
' <t:FieldURI FieldURI="item:Body"/>' +
' </t:AdditionalProperties>' +
' </ItemShape>' +
' <ItemIds><t:ItemId Id="' + id + '"/></ItemIds>' +
' </GetItem>';
return result;
}
// Create a local variable that contains the mailbox.
var mailbox = Office.context.mailbox;
var request = getHeadersRequest(mailbox.item.itemId);
var envelope = getSoapEnvelope(request);
var callback = function (data) {
var $data = $(data.value);
var $body = $("t\\:Body", $data);
deferred.resolve($body.html());
}
mailbox.makeEwsRequestAsync(envelope, callback);
return deferred.promise;
};
对于解决方案2),使用.NET Exchange SDK
And for solution 2) with .NET Exchange SDK
ExchangeService service = new ExchangeService();
service.Credentials = new OAuthCredentials(token);
service.Url = new Uri(ewsUrl);
PropertyDefinition definition = ItemSchema.NormalizedBody;
var propertySet = new PropertySet(definition, ItemSchema.Attachments,
ItemSchema.HasAttachments);
EmailMessage ewsEmail = EmailMessage.Bind(service, new ItemId(itemId), propertySet);
return ewsEmail.NormalizedBody.Text;
这篇关于Outlook Web App(Exchange 2013内部部署)API 1.2如何访问电子邮件正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!