cancel
Showing results for 
Search instead for 
Did you mean: 

Outlook - How To Extract Email ID using Employee Number

ShwetaSingh
Level 2

Hi,

Is there a way to get email address based on the Employee number (format of Employee number - 1234567) from Outlook?

I'm using the Outlook VBO, and in Outlook Address book Advanced find, I don't have the option to search with Employee Number. But as per the requirement, I just have an Employee Number and using that I need to extract the Email address (We  get it manually by CTRL+K command).

Please help.

Thank you.

2 REPLIES 2

expertcr
Staff
Staff

At this moment, our MS Outlook VBO does not have that option.

You will need to create a process that opens Outlook and look for that information.

uzershaikh1
Level 3

Extract Email ID and his Managers Email ID using Employee Number.

Thanks for the Solution @SwetaSingh

🚀 Check out this powerful code snippet for Active Directory user retrieval! 🌐

Are you looking to streamline your automation processes? This code is a game-changer. It efficiently fetches user and manager details from the Active Directory, ensuring seamless data retrieval for your automation tasks.

🔍 With meticulous handling for user existence, error management, and retrieval of manager details, this code snippet sets the standard for precise, error-free automation.

Discover the efficiency of user and manager data extraction and elevate your automation game with this expertly crafted code!

Initailization :

35667.png

35668.png

Code: 

success = false;
message = "An error occurred."; // Default error message
EmailID = "";
ManagerEmailID = "";
exist = false;

try
{
    using (PrincipalContext context = new PrincipalContext(ContextType.Domain, AD_DomainName))
    {
        using (UserPrincipal user = UserPrincipal.FindByIdentity(context, System.DirectoryServices.AccountManagement.IdentityType.SamAccountName, userName))
        {
            if (user != null)
            {
                exist = true;
                EmailID = user.EmailAddress;

                // Retrieve the user's manager
                if (user.GetUnderlyingObject() is DirectoryEntry directoryEntry && directoryEntry.Properties.Contains("manager"))
                {
                    string managerDistinguishedName = directoryEntry.Properties["manager"].Value?.ToString();

                    // Fetch manager details by distinguished name
                    if (!string.IsNullOrEmpty(managerDistinguishedName))
                    {
                        using (UserPrincipal manager = UserPrincipal.FindByIdentity(context, System.DirectoryServices.AccountManagement.IdentityType.DistinguishedName, managerDistinguishedName))
                        {
                            if (manager != null)
                            {
                                ManagerEmailID = manager.EmailAddress;
                                success = true; // Update success flag upon successful retrieval
                                message = ""; // Clear error message on success
                            }
                        }
                    }
                }
            }
            else
            {
                // Handle case when user doesn't exist
                message = "User not found in Active Directory.";
            }
        }
    }
}
catch (Exception e)
{
    message = e.Message; // Update error message with the exception details
    // Log the exception or handle it as needed
}
Action: 
35669.png
35670.png
#BluePrism #AutomationDeveloper #CodeEfficiency #ActiveDirectory #AutomationExperts
Uzer Shaikh | Consultant – Automation Developer
Wonder Botz Pvt Ltd.
Uzer Shaikh - Developer Consultant – Automation Developer Wonder Botz Pvt Ltd. Ahmedabad, India