gpt4 book ai didi

outlook-addin - Outlook Web App (Exchange 2013 On-Premise) API 1.2 如何访问电子邮件正文?

转载 作者:行者123 更新时间:2023-12-03 20:19:40 26 4
gpt4 key购买 nike

Office.context.mailbox.item.body给出 null 而
Office.context.mailbox.item.body.getAsync()仅适用于 JavaScript API 1.3 .

有什么办法可以用 JavaScript API 1.1/1.2 来获取邮件正文吗? ?

最佳答案

是的你可以。实际上,您将使用 Exchange Web 服务检索正文。

如解释 here有两种方法可以做到这一点:1)来自 javascript(客户端应用程序)的 SOAP 请求或 2)使用 SDK(例如 .NET Exchange Web SDK)的服务器端

对于解决方案 1),您的请求可能类似于以下 js 片段(请注意,我使用了带有 that.$q.defer(); 的 angular.js promise ,但这不是强制性的)

           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
            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-addin - Outlook Web App (Exchange 2013 On-Premise) API 1.2 如何访问电子邮件正文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36685110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com