Outlook mail accounts fetch dynamically

Hi,

I need to fetch the accounts associated in Outlook and use them dynamically.

Example: if a person is having two accounts in outlook,
The username is different for two accounts,

  1. ABC.xyz@company1.com
  2. xyz.abc@company2.com

So now I need username associated to company2.com (xyz.abc)

How to fetch the username??

Thanks
Bharath Bysani

@bbysani you can have a deep dive into the following VBA Code to get all the Mail accounts listed into Outlook. Ref. https://stackoverflow.com/questions/26519325/how-to-get-the-email-address-of-the-current-logged-in-user

Another Solution would be: Loop over folder “C:\Users<username>\AppData\Local\Microsoft\Outlook” and get the account email address from ost file extension.

Dim OL As Object, olAllUsers As Object, oExchUser As Object, oentry As Object, myitem As Object
Dim User As String

Set OL = CreateObject("outlook.application")
Set olAllUsers = OL.Session.AddressLists.Item("All Users").AddressEntries

User = OL.Session.CurrentUser.Name

Set oentry = olAllUsers.Item(User)

Set oExchUser = oentry.GetExchangeUser()

msgbox oExchUser.PrimarySmtpAddress

once you will get the email address simply use Account property to get the emails.
image

How would you input VBA code into UiPath (without using an Excel file to run a macro)?

@heykev75 welcome to the uipath community. You can not use Vba without excel

Thank you! If I assume the user has MS Excel on their machine, does the Excel file (with the VBA code) necessarily need to be on their machine too? Or can the Excel file (with the VBA code) just somehow reside within UiPath?

@heykev75 It is necessary to have Excel installed in order to use Excel application scope and under the scope only one can use Invoke VBA activity.
The other way without VBA is to use VB.net or vbscript

Thank you. Sorry to keep bothering. So that is my main question - how would you put the VB script into UiPath? For example, your code above for getting the user email address from Outlook - where would you put this code? In an Assign activity? thanks!

Never mind - I think I found it!