Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:35:49+00:00 2026-06-09T12:35:49+00:00

i’m developing an outlook addin for Outlook 2007. In short: I need to get

  • 0

i’m developing an outlook addin for Outlook 2007. In short: I need to get the active directory user principal object of the e-mails sender when a user opens an e-mail.

What I am trying to achieve:

  1. Get the sender of this e-mail
  2. Get the corresponding active directory account behind this sender
  3. Get a specific attribute of this ad-account (“physicalDeliveryOfficeName”)

I can handle step 1 and 3, but I don’t know how to get the link between the exchange-user-account and the active directory account

What I tried

string senderDisplayName = mailItem.SenderName;

Finding a user by displayname is impossible due to duplicates

string senderDistinguishedName = mailItem.SenderEmailAddress;

This will return something like “O=Company/OU=Some_OU/CN=RECIPIENTS/CN=USERNAME”
I can extract the username of this string, but this “username” is the username of the user’s mailbox or something like that. It doesn’t always match the active directory user name.

Is there a way to get the active directory user behind the sender-object?

Environment

  • Outlook 2007 / C# .NET 4
  • Exchange 2010
  • Active Directory
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:35:50+00:00Added an answer on June 9, 2026 at 12:35 pm

    The technique described below assumes the Exchange Mailbox Alias matches your AD Account ID.

    First you need to create a Recipient from the Exchange address, resolve the Recipient to an ExchangeUser, and then integrate PrincipalContext for searching AD by account ID. Once the UserPrincipal is located, you can query the DirectoryEntry for custom AD properties.

    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();
                }
            }
        }
    }
    

    Note: For AD integration, you need references to System.DirectoryServices and System.DirectoryServices.AccountManagement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.