由于Office API中消息大小的限制,我试图构建一种服务:
限制:
我尝试过getUserIdentityToken,但这对凭据没有用。
Office JS调用
var _appName;
var _mailbox;
var _emailAddress;
var _itemId;
var _identityToken;
var _ewsUrl;
app.initialize();
_mailbox = Office.context.mailbox;
var item = _mailbox.item;
_itemId = item.itemId;
_ewsUrl = _mailbox.ewsUrl;
_emailAddress = _mailbox.userProfile.emailAddress;
function MakeRequest(serviceUrl, callType, format) {
_mailbox.getCallbackTokenAsync(function (asyncResult) {
if (asyncResult.error) {
app.showNotification(_appName, "Error getting Use Identity Token: " + asyncResult.error.message);
}
else {
_identityToken = asyncResult.value;
var correctedItemId = _itemId.replace("+", "_");
var request = { ItemId: correctedItemId, UserEmailAddress: _emailAddress, UserIdentityToken: _identityToken, EwsUrl: _ewsUrl, AudienceUrl: _audUrl, ReturndNewId: false };
$.ajax({
crossDomain: true,
url: serviceUrl,
type: callType,
data: JSON.stringify(request),
contentType: 'application/json; charset=utf-8',
dataType: format,
success: function (asyncResultSuccess) {
LogResult(asyncResultSuccess.statusText);
//app.showNotification(_appName, asyncResultSuccess.statusText);
},
error: function (asyncResultError) {
LogResult(asyncResultError.statusText);
//app.showNotification(_appName, asyncResultError.statusText);
}
});
}
});
}
服务器端凭证:
void LoadSimple()
{
try
{
service = new ExchangeService(ExchangeVersion.Exchange2013_SP1)
{
Credentials = new TokenCredentials(RequestProperties.UserIdentityToekn),
Url = new Uri(RequestProperties.EwsUrl)
};
ReturnProps = new EwsReturnItem();
}
catch (Exception ex)
{
log.Error(string.Format("{0}: {1}", MethodBase.GetCurrentMethod().Name, ex.Message));
}
}
服务器端转发消息:
public EwsReturnItem Forward(string toRecipient, string ccRecipient, string subjectPrepend, string bodyText)
{
try
{
var correctedId = CorrectItemId(RequestProperties.ItemId);
EmailMessage email = EmailMessage.Bind(service, correctedId, new PropertySet(ItemSchema.MimeContent, ItemSchema.Subject));
ResponseMessage forwardMessage = email.CreateForward();
forwardMessage.Subject = String.Format("{0}{1}", subjectPrepend, email.Subject);
forwardMessage.ToRecipients.Add(toRecipient);
forwardMessage.CcRecipients.Add(ccRecipient);
forwardMessage.BodyPrefix = bodyText;
...snip
}
catch (Exception ex)
{
log.Error(string.Format("{0}: {1}", MethodBase.GetCurrentMethod().Name, ex.Message));
return new EwsReturnItem() { StatusText = ex.Message };
}
}
此行由于未授权而失败:
EmailMessage email = EmailMessage.Bind(service, correctedId, new PropertySet(ItemSchema.MimeContent, ItemSchema.Subject));