Search This Blog

Showing posts with label account information in outlook. Show all posts
Showing posts with label account information in outlook. Show all posts

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

Featured Posts

Unlock Hidden Windows Startup and Shutdown Details : How to Enable Verbose Startup and Shutdown Messages in Windows 11

WINDOWS TROUBLESHOOTING · FULL GUIDE Unlock Hidden Windows Startup and Shutdown Details Enable Verbose Status...