2012-08-09 3 views
3

Outlook 2007에 대한 Outlook 추가 기능을 개발 중입니다. 요컨대, 사용자가 전자 메일을 열 때 전자 메일 보낸 사람의 활성 디렉터리 사용자 주체 개체를 가져와야합니다. -우편.Outlook.MailItem에서 보낸 사람 Active Directory 사용자 원칙을 얻으십시오.

  1. 이 AD-의 특정 속성을 가져
  2. 이 보낸
  3. 뒤에 해당 Active Directory 계정을 얻으이 전자 메일의 보낸 사람을 가져 오기 : 내가 달성하기 위해 노력하고 무엇

    계정 ("physicalDeliveryOfficeName")

1 단계와 3 단계는 처리 할 수 ​​있지만 교환 사용자 간의 연결을 얻는 방법을 모르겠다. 계정과 내가 표시 이름하여 사용자로 인해 중복

string senderDistinguishedName = mailItem.SenderEmailAddress; 

이 O = 회사/OU "와 같은 무언가를 반환하는 것은 불가능 찾기

string senderDisplayName = mailItem.SenderName; 

을 시도 무엇 Active Directory 계정

= Some_OU/CN = RECIPIENTS/CN = USERNAME " 이 문자열의 사용자 이름을 추출 할 수 있지만이"사용자 이름 "은 사용자의 사서함 또는 이와 비슷한 사용자 이름입니다. 항상 활성 디렉토리 사용자 이름과 일치하지는 않습니다.

발신자 개체 뒤에 활성 디렉토리 사용자를 얻는 방법이 있습니까?

환경

  • 아웃룩 2007/C는 # .NET을 4
  • Exchange 2010을
  • Active Directory는

답변

2

Exchange 사서함 별칭일치 아래에 설명 된 기술은 가정합니다 광고 계정 ID.

먼저 당신은 Exchange 주소에서 Recipient을 만들 ExchangeUserRecipient를 해결 한 다음 계정 ID에 의해 AD 검색을위한 PrincipalContext을 통합 할 필요가있다. UserPrincipal이 있으면 사용자 지정 AD 속성에 대해 DirectoryEntry을 쿼리 할 수 ​​있습니다.

string deliveryOffice = string.Empty; 
Outlook.Recipient recipient = mailItem.Application.Session.CreateRecipient(mailItem.SenderEmailAddress); 
if (recipient != null && recipient.Resolve() && recipient.AddressEntry != null) 
{ 
    Outlook.ExchangeUser exUser = recipient.AddressEntry.GetExchangeUser(); 
    if (exUser != null && !string.IsNullOrEmpty(exUser.Alias)) 
    { 
     using (PrincipalContext pc = new PrincipalContext(ContextType.Domain)) 
     { 
      UserPrincipal up = UserPrincipal.FindByIdentity(pc, exUser.Alias); 
      if (up != null) 
      { 
       DirectoryEntry directoryEntry = up.GetUnderlyingObject() as DirectoryEntry; 
       if (directoryEntry.Properties.Contains("physicalDeliveryOfficeName")) 
        deliveryOffice = directoryEntry.Properties["physicalDeliveryOfficeName"].Value.ToString(); 
      } 
     } 
    } 
} 

: AD 통합을 위해, 당신은 System.DirectoryServicesSystem.DirectoryServices.AccountManagement에 대한 참조가 필요합니다.