Get Outlook Mail Message activity almost always returning null in output variable?

Hi all,

I’m trying to run fetch email attachments from new email messages. The problem is, even when there are new mail messages, sometimes the Get Outlook Mail Messages activity returns null (error: Log Message - MailMessage: Object reference not set to an instance of an object.), causing my automation to crash at the following Log Message/If statement that checks if the mail message count is greater than 0 (MailMessages.Count > 0). This rarely happens when I’m running in Studio, but happens almost constantly when running the automation from Orchestrator/unattended. Has anyone experienced this and found a solution? I’ve attached a screenshot of my workflow below.

Thanks in advance!

MailMessage is in the form of List
so please use for Each Activity and iterate it
and then you can get the count


Thanks for the reply, but I do have a For-Each (pictured bottom left of the screenshot), where I mark the message as read and move it to the Archive folder. Also, a For-Each is not needed to retrieve the count of MailMessages.


you are counting the list as you mentioned in if condition
it will not work

you have to keep in for each then it will count the mail in MailMessages


MailMessages, my output variable of the Get Outlook Mail Messages activity, is a list of type MailMessage. That list has the Count property, which does return the count (docs: List.Count Property (System.Collections.Generic) | Microsoft Docs).

I should note that this logic works on my machine running in Studio, but not on my unattended robot starting from Assistant/Orchestrator.

My question is: Why is it returning null when a) there are unread messages in the mailbox, and b) it marks those very messages as read?

Did you solve this problem?
Im running into the same problem sometimes - the mail message activity is returning null when run on an robot even if there’s messages in the inbox - when Im running in Studio it always works.

Hi, yes, I was able to solve the problem. I had to retrieve messages one by one using the Get Outlook Mail Messages activity and then check that the output was not Nothing before going on to save any attachments or mark as read. I’ve attached an image of my process below with annotations. Hope this helps!

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