Tuesday, January 25, 2011

How to get Current Outlook version installed and Current configured Email ID in C#.net?

Here is the code to retrieve the current outlook version installed like outlook 2003 or Outlook 2007 in C#.Net etc.

 public static string GetOutlookVersion()
       {
           Microsoft.Office.Interop.Outlook.Application applicationObject = new

Microsoft.Office.Interop.Outlook.Application();
           return applicationObject.Version;
       }

The following code gives you the current configured email id for outlook.There will be no issues whether it will be a POP3 account or it may be an exchange server account.

 public static string GetCurrentUser()
       {
           string currentUser = string.Empty;
           try
           {
               RDOSessionClass session = new RDOSessionClass();
               session.Logon("", "", false, false, null, false);

               RDOAccounts accounts = session.Accounts;
               foreach (RDOAccount account in accounts)
               {
                   if (account.AccountType == rdoAccountType.atPOP3)
                   {

                       currentUser = session.CurrentUser.Address;
                   }
                   else if (account.AccountType == rdoAccountType.atExchange)
                   {
                       currentUser = session.CurrentUser.SMTPAddress;
                   }
               }
           }
           catch (System.Exception ex)
           {            
           }
           return currentUser;
       }

You can try out more for any further need like if multiple accounts have been configured.

No comments:

Post a Comment