Get Cc receipients from Outlook Mails

Hi Devs, pls I have bben trying to get the Cc reciepients from mail but it seems not working from me, pls any updated way to get it would be appreciated. N/B I have used
for each mail in mailMessages
if mail.headers(“Cc”).ToString.Contains(“cashIn”), it still didn’t work

@komi
Did you try in loop

mail.CC.ToString.Contains(“cashIn”)

CC Property will return a System.Net.Mail.MailAddressCollection
grafik

So we can check e.g. within the addresses with
grafik

YourMailVar.CC.Any(Function (x) x.Address.Contains("cashin"))

ToString() will return for an MailAddressCollection (with only 1 ID contained)
grafik
we got the name (red) and the address (blue)

1 Like

Hi @ppr, is the variable to be used list variable here - YourMailVar.CC.Any(Function (x) x.Address.Contains(“cashin”))

If not list, is there a better way to write the query without using for each loop pls?

similar to your approach:

YourMailVar is the single mail from loop
CC is of MailAdressCollection and the given code check for the loop in all CC Adresses

checking all emails from the returned mails and checking in all cc addresses

isFoundInAnyMail =

YourGetMailsOutVar.Any(Function (m) m.CC.Any(Function (x) x.Address.Contains("cashIn")))

Thanks @ppr

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.