Get a distribution list from an email CC inside outlook

Hi all, I have received an email with a distribution list inside the CC field.
The distribution list is a single email, but multiple members are contained inside when you expand the list.

When i try to use UIPath to obtain the CC recipient(get outlook mail message->ListMessages(0).CC.ToString), UiPath returns a null value.
Is there any way I can obtain the distribution list email as the CC recipient?

Could this help?

This does not work because the email is a distribution list. It returns null as the CC recipient. I would love to send you a sample email for testing but unfortunately the email is work related, so sorry about that.

i dont think you can just do CC.toString
mailMessage(0).CC will be image

So you need to loop and get one value of the collection and then print it.

1 Like

To extract all the emails Id from the distribution list you can try using shell script.

Step1- open Notepad and paste the following code and save it as .ps1 file

Note- You will get popup in run time where you have to enter your outlook Id and password

$o365cred = Get-Credential emailid@domain.com // enter your own outlook email id
$session365 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “https://ps.outlook.com/powershell/” -Credential $o365cred -Authentication Basic -AllowRedirection
Import-Module (Import-PSSession $session365 -AllowClobber) -Global
$DGName = “Distribution list email Id”
Get-DistributionGroupMember -Identity $DGName | Select PrimarySMTPAddress |
Export-CSV “D:\DlList.csv- File where email id are extracted” -NoTypeInformation -Encoding UTF8

Step 2- If you directly run the shell script or invoke the shell script - You may encounter error stating- "cannot be loaded because running scripts is disabled on this system. For more
information, see about_Execution_Policies "

to avoid the following error you can create a bat file to execute the shell script-
Steps for the same are as below-
Open a notepad and paste the below code and save it as .bat file

@echo off
color 1F
echo.

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "path of the shell script "
:EOF
echo Waiting seconds
timeout /t 40 /nobreak > NUL

Step 3 In the UiPath , you can use start process to start activity to launch the bat file
image

Thanks & Regards,
Lipika Porey

Hello @blueleaf, Is your problem fixed? because I face same issue :slight_smile: