Exchange Web Services 2010是否可以从任何电子邮件地址在邮箱中创建邮件?
所以场景是这样的; 用户收到电子邮件 服务在SQL中搜索电子邮件和存储(将消息存储为XML) 然后从邮箱中删除电子邮件 时间流逝... 服务采用SQL版本的电子邮件并创建回原始邮箱
我们之前遇到过一个交换安全问题,它不允许我们使用域外任何人的发件人对象创建电子邮件。例如,Mike @ MyDomain.com工作正常,但Bob@Microsoft.com无效。
我显然可以看到与解除此限制相关的安全风险,但这是我需要构建的系统的要求。
创建消息的实际代码在这里(大部分代码来自MSDN);
public void CreateEmail(string FromAddress, MessageType message)
{
ExchangeServiceBinding esb = getExchangeServiceBinding(FromAddress);
// Create the CreateItem request.
CreateItemType createItemRequest = new CreateItemType();
// Specifiy how the created items are handled
createItemRequest.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
createItemRequest.MessageDispositionSpecified = true;
// Specify the location of sent items.
createItemRequest.SavedItemFolderId = new TargetFolderIdType();
DistinguishedFolderIdType sentitems = new DistinguishedFolderIdType();
sentitems.Id = DistinguishedFolderIdNameType.sentitems;
createItemRequest.SavedItemFolderId.Item = sentitems;
// Create the array of items.
createItemRequest.Items = new NonEmptyArrayOfAllItemsType();
// Create a single e-mail message.
MessageType newmessage = new MessageType();
//Can't seem to restore the original message.
//If part of the email is being lost when restored then it's happening here.
//import original message into newmessage
newmessage.Subject = message.Subject;
newmessage.Body = message.Body;
newmessage.ItemClass = message.ItemClass;
newmessage.Sender = message.Sender;
newmessage.ToRecipients = message.ToRecipients;
newmessage.Sensitivity = message.Sensitivity;
newmessage.ExtendedProperty = message.ExtendedProperty;
newmessage.DateTimeSent = message.DateTimeSent;
newmessage.IsRead = true;
// Add the message to the array of items to be created.
createItemRequest.Items.Items = new ItemType[1];
createItemRequest.Items.Items[0] = newmessage;
try
{
// Send the request to create and send the e-mail item, and get the response.
CreateItemResponseType createItemResponse = esb.CreateItem(createItemRequest);
// Determine whether the request was a success.
if (createItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
{
throw new Exception(createItemResponse.ResponseMessages.Items[0].MessageText);
}
else
{
Console.WriteLine("Item was created");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
答案 0 :(得分:0)
我现在已经解决了这个问题。没有安全限制。使用Exchange WebServices,此代码工作正常。限制是使用托管Web服务API。创建消息时无法更改发件人/发件人对象。