Search This Blog

Tuesday, October 18, 2011

Get Information About Multiple Accounts in outlook


//namespace to use (add microsoft.office.interop.outlook dll )
using Outlook = Microsoft.Office.Interop.Outlook;
private void getallAccountsInOutlook()
{
    Outlook.Accounts accounts = Application.Session.Accounts;
    foreach (Outlook.Account account in accounts)
    {
        try
        {
            StringBuilder allInfoInThisString = new StringBuilder();
            allInfoInThisString.AppendLine("Account: " + account.DisplayName);
            if (string.IsNullOrEmpty(account.SmtpAddress)
                || string.IsNullOrEmpty(account.UserName))
            {
                Outlook.AddressEntry addressEntryObject =account.CurrentUser.AddressEntry as Outlook.AddressEntry;
                if (addressEntryObject.Type == "EX")
                {
                    Outlook.ExchangeUser oEU =
                        addressEntryObject.GetExchangeUser()
                        as Outlook.ExchangeUser;
                    allInfoInThisString.AppendLine("UserName: " +
                        oEU.Name);
                    allInfoInThisString.AppendLine("SMTP: " +
                        oEU.PrimarySmtpAddress);
                    allInfoInThisString.AppendLine("Exchange Server: " +
                        account.ExchangeMailboxServerName);
                    allInfoInThisString.AppendLine("Exchange Server Version: " +
                        account.ExchangeMailboxServerVersion); 
                }
                else
                {
                    allInfoInThisString.AppendLine("UserName: " +
                        addressEntryObject.Name);
                    allInfoInThisString.AppendLine("SMTP: " +
                        addressEntryObject.Address);
                }
            }
            else
            {
                allInfoInThisString.AppendLine("UserName: " +
                    account.UserName);
                allInfoInThisString.AppendLine("SMTP: " +
                    account.SmtpAddress);
                if(account.AccountType == 
                    Outlook.OlAccountType.olExchange)
                {
                    allInfoInThisString.AppendLine("Exchange Server: " +
                        account.ExchangeMailboxServerName);
                    allInfoInThisString.AppendLine("Exchange Server Version: " +
                        account.ExchangeMailboxServerVersion); 
                }
            }
            if(account.DeliveryStore !=null)
            {
                allInfoInThisString.AppendLine("Delivery Store: " +
                    account.DeliveryStore.DisplayName);
            }
            allInfoInThisString.AppendLine("_________________________");
            Debug.Write(allInfoInThisString.ToString());
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
    }
}

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

Discover powerful tools for digital investigations, IP intelligence, threat hunting, exposed services, data breach research and satellite imagery.

14 Powerful OSINT Tools for Cybersecurity | BytesXplorer </> Bytes Xplorer TECHNOLOGY • ...