我正在检查发件人是否使用了代理电子邮件地址。比较from和sender属性是不够的,所以我考虑检查原始消息源本身。
如何使用Office JS API获取原始消息源?
发布于 2018-07-06 05:34:51
如果你正在寻找一个预置的解决方案来查看和分析邮件头,你可以使用Message Header Analyzer。如果您正在构建自己的外接程序,您可以从那里借用源代码。
基本上,你有两个选择:
在这两种情况下,您希望检索的是PR_TRANSPORT_MESSAGE_HEADER,也就是0x007D。EWS请求将类似于this
function getHeadersRequest(id) {
// Return a GetItem EWS operation request for the headers of the specified item.
return "<GetItem xmlns='http://schemas.microsoft.com/exchange/services/2006/messages'>" +
" <ItemShape>" +
" <t:BaseShape>IdOnly</t:BaseShape>" +
" <t:BodyType>Text</t:BodyType>" +
" <t:AdditionalProperties>" +
// PR_TRANSPORT_MESSAGE_HEADERS
" <t:ExtendedFieldURI PropertyTag='0x007D' PropertyType='String' />" +
" </t:AdditionalProperties>" +
" </ItemShape>" +
" <ItemIds><t:ItemId Id='" + id + "'/></ItemIds>" +
"</GetItem>";
}
您将通过调用makeEwsRequestAsync提交它
var mailbox = Office.context.mailbox;
var request = getHeadersRequest(mailbox.item.itemId);
var envelope = getSoapEnvelope(request);
mailbox.makeEwsRequestAsync(envelope, function (asyncResult) {
callbackEws(asyncResult, headersLoadedCallback);
});
要从rest中执行相同的操作,首先需要获取项目的rest ID:
function getItemRestId() {
if (Office.context.mailbox.diagnostics.hostName === "OutlookIOS") {
// itemId is already REST-formatted
return Office.context.mailbox.item.itemId;
} else {
// Convert to an item ID for API v2.0
return Office.context.mailbox.convertToRestId(
Office.context.mailbox.item.itemId,
Office.MailboxEnums.RestVersion.v2_0
);
}
然后通过AJAX发送请求:
var getMessageUrl = getRestUrl(accessToken) +
"/api/v2.0/me/messages/" +
itemId +
// PR_TRANSPORT_MESSAGE_HEADERS
"?$select=SingleValueExtendedProperties&$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String 0x007D')";
$.ajax({
url: getMessageUrl,
dataType: "json",
headers: {
"Authorization": "Bearer " + accessToken,
"Accept": "application/json; odata.metadata=none"
}
}).done(function (item) {
MHA源代码提供了更多上下文。
https://stackoverflow.com/questions/51178945
复制相似问题