如何创建类别并将其应用于电子邮件
How to create a category and apply it to an email
是否可以通过编程方式在 Outlook 中创建类别?
我按照 MS 的教程设置了一个 hello world outlook-addin。我看到我如何访问特定电子邮件的所有不同属性。但是,我对如何使用类别感到困惑。
要创建类别,您必须使用 EWS 或 REST API。 Office.js 库今天不提供通过 javascript 直接设置类别的方法。
我必须通过 Office.context.mailbox.makeEwsRequestAsync()
传递以下 SOAP 请求以创建名为 "Muktader" 的类别并将其应用于由项目 ID 标识的电子邮件。
<?xml version="1.0" encoding="utf-8"?>
<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="Exchange2013_SP1" />
</soap:Header>
<soap:Body>
<m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite">
<m:ItemChanges>
<t:ItemChange>
<t:ItemId Id="AAMkAGVlOTZjNTM3LWVjNjgtNGZlNi04MTBkLWIyNjNjNWEyY2VlNABGAAAAAABpsgv3HB+wQJRg4K+r7AmBBwBJi9ckXu/REb74AIBfn0G8AAAUrOs1AACN8cPrPdSYR5RdhR69ULJ0AAACOkAqAAA=" ChangeKey="CQAAABYAAACN8cPrPdSYR5RdhR69ULJ0AAACR0YO" />
<t:Updates>
<t:SetItemField>
<t:FieldURI FieldURI="item:Categories" />
<t:Message>
<t:Categories>
<t:String>Muktader</t:String>
</t:Categories>
</t:Message>
</t:SetItemField>
</t:Updates>
</t:ItemChange>
</m:ItemChanges>
</m:UpdateItem>
</soap:Body>
</soap:Envelope>
使用 EWS SOAP 方法在 Outlook 中创建类别:
- 使用Office.context.mailbox.makeEwsRequestAsync()方法调用SOAP异步请求。
- 使用 SOAP 请求为电子邮件设置自定义类别
- 对结果使用 SOAP 请求响应
- 也可以创建主类别,然后将该类别用于需要颜色的电子邮件。
注意:同时使用 ReadWriteMailbox 权限更新 .xml 文件。还将当前电子邮件 itemID 和 ChangeKey 传递给 SOAP 请求。
使用Office.context.mailbox.makeEwsRequestAsync()方法调用SOAP异步请求。
Office.context.mailbox.makeEwsRequestAsync(updateItemRequest(itemID, changeKey), function (updateAsyncResult) {
if (updateAsyncResult.status === "failed") {
var error = updateAsyncResult.error;
console.log("error " + error.name + ": " + error.code + " - " + error.message);
}
else {
console.log("Result: " + updateAsyncResult.value);
}
});
使用 SOAP 请求为电子邮件设置自定义类别
function updateItemRequest(id, changeKey) {
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:Header>\
<t:RequestServerVersion Version="Exchange2013" />\
</soap:Header>\
<soap:Body>\
<UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">\
<ItemChanges>\
<t:ItemChange>\
<t:ItemId Id =\"' + id + '\" ChangeKey=\"' + changeKey + '\" />\
<t:Updates>\
<t:SetItemField>\
<t:FieldURI FieldURI = "item:Categories" />\
<t:Message>\
<t:Categories>\
<t:String>CategoryName</t:String>\
</t:Categories>\
</t:Message>\
</t:SetItemField>\
</t:Updates>\
</t:ItemChange>\
</ItemChanges>\
</UpdateItem>\
</soap:Body >\
</soap:Envelope >';
console.log("Log update request: " + request);
return request;
}
是否可以通过编程方式在 Outlook 中创建类别?
我按照 MS 的教程设置了一个 hello world outlook-addin。我看到我如何访问特定电子邮件的所有不同属性。但是,我对如何使用类别感到困惑。
要创建类别,您必须使用 EWS 或 REST API。 Office.js 库今天不提供通过 javascript 直接设置类别的方法。
我必须通过 Office.context.mailbox.makeEwsRequestAsync()
传递以下 SOAP 请求以创建名为 "Muktader" 的类别并将其应用于由项目 ID 标识的电子邮件。
<?xml version="1.0" encoding="utf-8"?>
<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="Exchange2013_SP1" />
</soap:Header>
<soap:Body>
<m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite">
<m:ItemChanges>
<t:ItemChange>
<t:ItemId Id="AAMkAGVlOTZjNTM3LWVjNjgtNGZlNi04MTBkLWIyNjNjNWEyY2VlNABGAAAAAABpsgv3HB+wQJRg4K+r7AmBBwBJi9ckXu/REb74AIBfn0G8AAAUrOs1AACN8cPrPdSYR5RdhR69ULJ0AAACOkAqAAA=" ChangeKey="CQAAABYAAACN8cPrPdSYR5RdhR69ULJ0AAACR0YO" />
<t:Updates>
<t:SetItemField>
<t:FieldURI FieldURI="item:Categories" />
<t:Message>
<t:Categories>
<t:String>Muktader</t:String>
</t:Categories>
</t:Message>
</t:SetItemField>
</t:Updates>
</t:ItemChange>
</m:ItemChanges>
</m:UpdateItem>
</soap:Body>
</soap:Envelope>
使用 EWS SOAP 方法在 Outlook 中创建类别:
- 使用Office.context.mailbox.makeEwsRequestAsync()方法调用SOAP异步请求。
- 使用 SOAP 请求为电子邮件设置自定义类别
- 对结果使用 SOAP 请求响应
- 也可以创建主类别,然后将该类别用于需要颜色的电子邮件。 注意:同时使用 ReadWriteMailbox 权限更新 .xml 文件。还将当前电子邮件 itemID 和 ChangeKey 传递给 SOAP 请求。
使用Office.context.mailbox.makeEwsRequestAsync()方法调用SOAP异步请求。
Office.context.mailbox.makeEwsRequestAsync(updateItemRequest(itemID, changeKey), function (updateAsyncResult) {
if (updateAsyncResult.status === "failed") {
var error = updateAsyncResult.error;
console.log("error " + error.name + ": " + error.code + " - " + error.message);
}
else {
console.log("Result: " + updateAsyncResult.value);
}
});
function updateItemRequest(id, changeKey) {
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:Header>\
<t:RequestServerVersion Version="Exchange2013" />\
</soap:Header>\
<soap:Body>\
<UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">\
<ItemChanges>\
<t:ItemChange>\
<t:ItemId Id =\"' + id + '\" ChangeKey=\"' + changeKey + '\" />\
<t:Updates>\
<t:SetItemField>\
<t:FieldURI FieldURI = "item:Categories" />\
<t:Message>\
<t:Categories>\
<t:String>CategoryName</t:String>\
</t:Categories>\
</t:Message>\
</t:SetItemField>\
</t:Updates>\
</t:ItemChange>\
</ItemChanges>\
</UpdateItem>\
</soap:Body >\
</soap:Envelope >';
console.log("Log update request: " + request);
return request;
}