Getting accounts from Outlook 2007 using VB.NET in VSTO
- by Pranav
This is a sample code for getting Email accounts which are configured in Outlook 2007. This is developed using native code of VSTO. We can also implement is using 3rd party libraries like Redemption.
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!