Возможно ли в Exchange Web Services 2010 создать сообщение в почтовом ящике с любого адреса электронной почты?
Итак, сценарий таков;
Пользователь получает электронную почту,
Сервис отбирает почту и сохраняет в SQL (сохраняет сообщение в формате XML)
Email затем удален из почтового ящика
Время проходит...
Служба принимает версию электронной почты 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);
}
}