none
Have user's alias and name, need to get user's manager RRS feed

  • Question

  • using Microsoft.Office.Interop.Outlook;

    I have a user's alias, full name, and internal email.

    However, my real goal is to get an ExchangeUser object so I can get the user's manager. However when I use MailItem.Recipients.Add(email) I don't get a fully resolved user (ExchangeUser() returns null); when I use MailItem.Recipients.Add(alias) or MailItem.Recipients.Add(name) it doesn't resolve presumably due to the fact that the name is not unique and the alias may partially match other users.

    Any suggestions as to how I can use the information I have to get an ExchangeUser object? I did manage to create a System.DirectoryServices.AccountManagement.UserPrincipal object, but still don't know how to get to an ExchangeUser from there.

    Tuesday, November 5, 2013 8:41 PM

Answers

  • I found a solution. 

    var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(TEAM_PROJECT_COLLECTION_URI);

    var IdentityManagementService = (IIdentityManagementService)tfs.GetService(typeof(IIdentityManagementService));

    var identity = IdentityManagementService.ReadIdentity(IdentitySearchFactor.DisplayName, "my_user", MembershipQuery.Direct, ReadIdentityOptions.None); var domain = new PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain, "my_domain"); var user = UserPrincipal.FindByIdentity(domain, IdentityType.Sid, identity.Descriptor.Identifier);

    var myRecipient = myMailItem.Recipients.Add(user.EmailAddress);

    myRecipient.Resolve(); var manager = myMailItem.Recipients.Add(myRecipient.AddressEntry.GetExchangeUser.GetExchangeUserManager().Address);

    manager.Type = (int) Outlook.OlMailRecipientType.olCC;

    It seems the issue was that the email address I had for the user is not the user's primary email. Most users have alias@domain as primary whereas this user has first.last@domain





    Wednesday, November 6, 2013 12:52 AM

All replies

  • By "internal email", do you mean the EX type address? Or is it SMTP?

    Will Namespace.CreateRecipient / Recipient.Resolve return an SMTP or an EX type address entry?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, November 5, 2013 9:02 PM
  • SMTP
    Tuesday, November 5, 2013 10:12 PM
  • Does Outlook itself resolve that adders to an EX address when you type it in the To edit box and hit Ctrl+K?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, November 5, 2013 10:14 PM
  • I don't really know how to tell. In the To: box when I click "Check Names" it still shows "user@domain.com" although it does detect the user's presence and hovering over that user shows the correct user. But normally it would show the user's name in the To: box.
    Tuesday, November 5, 2013 10:37 PM
  • If you see Exchange data if double click on that recipient, Namespace.CreateRecipient / Recipient.Resolve will give you the Exchange user.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, November 5, 2013 10:40 PM
  • Double clicking brings up a "contact card" which identifies the user correctly. However right clicking and selecting "Email Properties" gives me an "E-mail Properties" dialog which gives the E-mail type as SMTP.

    In any case the issue is that Recipient.Resolve does not give me the Exchange User. Resolve is successful but the Recipient.AddressEntry.Type is "SMTP".

    I guess what I was imagining a way to do an exact match on the user's alias (you'd think a unique identifier would be enough, right?) or to somehow acquire the ExchangeUser via its associated Active Directory account. But anything that gets me the ExchangeUser would do.

    Appreciate your continued effort.

    Tuesday, November 5, 2013 11:10 PM
  • Or, is there a way to iterate over the matches to the alias so I can select the one that exactly matches?
    Tuesday, November 5, 2013 11:13 PM
  • Not in the Outlook Object Model. In Redemption you can use RDOSesion.AddressBook.ResolveNameEx(http://www.dimastr.com/redemption/rdoaddressbook.htm), which returns a list of matches.

    You can also use RDOSession.AddressBook.GAL.ResolveName/ResolveNameEx


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, November 5, 2013 11:16 PM
  • I found a solution. 

    var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(TEAM_PROJECT_COLLECTION_URI);

    var IdentityManagementService = (IIdentityManagementService)tfs.GetService(typeof(IIdentityManagementService));

    var identity = IdentityManagementService.ReadIdentity(IdentitySearchFactor.DisplayName, "my_user", MembershipQuery.Direct, ReadIdentityOptions.None); var domain = new PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain, "my_domain"); var user = UserPrincipal.FindByIdentity(domain, IdentityType.Sid, identity.Descriptor.Identifier);

    var myRecipient = myMailItem.Recipients.Add(user.EmailAddress);

    myRecipient.Resolve(); var manager = myMailItem.Recipients.Add(myRecipient.AddressEntry.GetExchangeUser.GetExchangeUserManager().Address);

    manager.Type = (int) Outlook.OlMailRecipientType.olCC;

    It seems the issue was that the email address I had for the user is not the user's primary email. Most users have alias@domain as primary whereas this user has first.last@domain





    Wednesday, November 6, 2013 12:52 AM
  • You cannot make any assumptions about how an SMTP address is constructed. SMTP addresses are not necessarily related in any way to the alias, first, or last names.

    If you were using Extended MAPI (C++ or Delphi), your could use PR_SEARCH to search for the PR_ACCOUNT property.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, November 6, 2013 4:38 AM