Check if maillist is empty

I have set up a flow that uses the Exchange Mail Message function, output is list called “maillist” (variable type List).
I would like to throw an expection, in case the list is empty and have added an IF function, where the condition is ‘IsNothing(maillist)’ - or ‘maillist is nothing’ - but it does not throw an exception. If there are no emails in the mailbox, ‘maillist’ contains: ‘List(0) { }’ so technically it is not “nothing”.
How do I make the if statement understand that it is empty?

Hi @NielsOlsen

Check this condition


Ashwin S

@NielsOlsen - If List<System.Net.Mail.MailMessage> is Mail_Exc of Exchange Mail Message you can use Mail_Exc.Count if count is zero that means list is empty.

I just get a compiler error:


How do I use the Mail_Exc.Count - do you have an example?

Hi @NielsOlsen

use for each item in Maillist

and then use String.IsNullorEmpty(item.ToString)

Ashwin S

Check the count of list along with your existing condition. It solves your case.

This solution still eludes me. I have setup the following:

But when I run it in debug mode, it never enters the for each loop, it just closes the loop and goes to the default exception. I see that “item” is empty:

so why would it not run through the loop as expected?

can you please share the properties screenshot of for each?

Here it is:

I’m guessing I missed something here?

change type argument to mail message and check

Done and I get the same result


Check the count of mail message and print it before for each and check pls.

Are you getting any counts there?

I dont think so, it stops the for each as soon as it starts:

I get this from the message details, not sure if it helps:
“Arguments”: {
“Values”: “System.Collections.Generic.List`1[System.Net.Mail.MailMessage]”,
“CurrentIndex”: “0”

Have you created the variable for list of mail message (Output of Exchange Mail activity) ?

If not create a variable and initialize it and check please.

Confirm whether you have any count in the list or not?

Put a message box before for each and check the count first. then proceed with for each

I have a variabel for mailist type: List

I have added a message box with “maillist.Count” it gives me “0”

check in if condition and process if you feel easy .

if count >0 proceed with for each else exit the loop saying no count

If there are no emails in maillist, it never attempts to process the IF statement, no matter what I type into it. This is what puzzles me.

Not sure if this is what you meant, but I skiped the for each and just added an IF maillist.Count.ToString() = “0” - and it works now.

Thanks for the help :slight_smile: