2012-07-04 2 views
3

Exchange에 연결된 Outlook에서 인터넷 형식의 주소를 읽으려고합니다. Outlook 연락처 (즉, GAB (Global Address Book)이 아닌)에서 모든 연락처를 읽었습니다. 문제는 Exchange GAB의 연락처에 저장되어있는 모든 사용자에 대해 X.500 형식을 읽었을 때만 읽을 수 있다는 것입니다. 주소는이 경우 유용하지 않습니다. Exchange 서버의 도메인에없는 수동으로 추가 한 모든 연락처의 경우 인터넷 주소가 예상대로 내보내집니다.Exchange Outlook 연락처에서 인터넷 전자 메일 주소 받기 프로그래밍 방식으로?

static void Main(string[] args) 
{ 
    var outlookApplication = new Application(); 
    NameSpace mapiNamespace = outlookApplication.GetNamespace("MAPI"); 
    MAPIFolder contacts = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderContacts); 

    for (int i = 1; i < contacts.Items.Count + 1; i++) 
    { 
     try 
     { 
      ContactItem contact = (ContactItem)contacts.Items[i]; 
      Console.WriteLine(contact.FullName); 
      Console.WriteLine(contact.Email1Address); 
      Console.WriteLine(contact.Email2Address); 
      Console.WriteLine(contact.Email3Address); 
      Console.WriteLine(); 
     } 
     catch (System.Exception e) { } 
    } 
    Console.Read(); 
} 

대신 X.500의 인터넷 주소를 추출 할 수있는 방법이 있나요 :

는 기본적으로 나는 연락처를 열거하려면 다음 코드를 사용했습니다?

답변

4

ContactItem에서 AddressEntry (한 번에 하나의 이메일 주소)로 변환해야합니다.

이렇게하려면 Recipient 개체 모델을 통해 AddressEntry에 액세스해야합니다. 실제 수신자 EntryID을 검색하는 유일한 방법은 leveraging the PropertyAccessor of the ContactItem입니다.

const string Email1EntryIdPropertyAccessor = "http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/80850102"; 
string address = string.Empty; 
Outlook.Folder folder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts) as Outlook.Folder; 
foreach (var contact in folder.Items.Cast<Outlook.ContactItem>().Where(c=>!string.IsNullOrEmpty(c.Email1EntryID))) 
{ 
    Outlook.PropertyAccessor propertyAccessor = contact.PropertyAccessor; 
    object rawPropertyValue = propertyAccessor.GetProperty(Email1EntryIdPropertyAccessor); 
    string recipientEntryID = propertyAccessor.BinaryToString(rawPropertyValue); 
    Outlook.Recipient recipient = this.Application.Session.GetRecipientFromID(recipientEntryID); 
    if (recipient != null && recipient.Resolve() && recipient.AddressEntry != null) 
     address = recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress; 
} 
+0

답변을받은 후 꽤 오랜 시간이 걸렸습니다. 내가'Email2EntryID'와'Email3EntryID'를 얻기 위해 어떻게 위의 코드를 수정할 수 있는지 안내해 줄 수 있습니까? 나는 그들의 GUID (유일한 차이점이 될 것처럼 보이지만)를 인터넷을 통해 찾고 있었지만 아직 발견하지 못했다. – dotNET

+0

신경 쓰지 마세요. 내 질문을 게시하는 순간 나는 ID가 모두있는 Microsoft 페이지를 찾았습니다. 관심있는 사람은 마지막 부분 (80850102)을 Email2의 경우 80950102로 변경하고 Email3의 경우에는 80A50102로 변경하십시오. – dotNET

관련 문제