How to get accounts from Outlook 2007?

Here is the sample code for getting Account Name and Email Address from Outlook 2007 using VSTO.
Dim olAccounts As Outlook.Accounts = Globals.ThisAddIn.Application.ActiveExplorer().Session.Accounts
Dim acc As Outlook.Account
MessageBox.Show(“No. of accounts: ” & olAccounts.Count.ToString)
If olAccounts.Count > 0 Then
ReDim emails(olAccounts.Count)
For Each acc In olAccounts
MessageBox.Show(“Name: ” & acc.UserName & “Email: ” & acc.SmtpAddress)
Marshal.ReleaseComObject(acc)
Next
Else
MessageBox.Show(“There are no accounts in Outlook”)
End If

Hope this helps!

Leave a Comment

Your email address will not be published. Required fields are marked *