2011-03-10 5 views
0

Exchange Web Services 2010에서 모든 전자 메일 주소의 사서함에 메시지를 만들 수 있습니까?모든 전자 메일 주소에 대한 EWS CreateItemResponse

시나리오는 다음과 같습니다. 사용자가 이메일을 수신, 서비스는 SQL의 이메일 저장 이메일 다음 사서함 시간이 지남에 에서 삭제 (저장 XML과 같은 메시지를) 보러 ... 서비스는 이메일의 SQL 버전을 받아 원래 사서함

로 다시 생성 이전에는 Exchange 보안 문제가 발생하여 도메인 외부의 사람의 보낸 사람 개체를 사용하여 전자 메일을 만들지 못했습니다. 예를 들어 [email protected]은 잘 작동했지만 [email protected]은 작동하지 않았습니다.

이 제한을 해제하는 것과 관련된 보안 위험은 분명하지만 설치해야하는 시스템에 대한 요구 사항입니다.

메시지를 작성하기위한 실제 코드는 여기에 있습니다 (대부분의 코드는 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

이제이 문제를 정리했습니다. 보안 제한이 없었습니다. Exchange WebServices를 사용하면이 코드가 정상적으로 작동합니다. 이 제한은 Managed Web services API를 사용하여 제한되었습니다. 메시지를 만들 때 보낸 사람/보낸 사람 개체를 변경할 방법이 없습니다.

관련 문제