Powered by Blogger.

Sunday, February 23, 2014

Get Current Outlook version installed and Current configured Email ID in C#.net



In this post we will discuss how to get Current Outlook version installed and Current configured Email ID in C#.net. Also you can check out my previous posts on:

- Set maximum length for multiline textbox in Asp.Net

- Read all outlook calendar items using C#.net using outlook APIs

- Delete record using enterprise library in Asp.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.