I’m trying to create a condition by using the IF activity and get an error of:
Object reference not set to an instance of an object
the condition should be
mail.Subject.ToString.Contains(“SOA Request 1st Attempt”) and mail.body.ToString.Contains(“Delivery has failed to these recipients,Your message couldn’t be delivered to multiple recipients.”) AndAlso mail.From.ToString.Contains(“Microsoft Outlook,PostMaster,postmaster@xmalimited.onmicrosoft.com”)
The error message “Object reference not set to an instance of an object” in UiPath typically occurs when your workflow is trying to access or use an object that has not been initialized.
Check if your mail variable is not nothing before using it.
I’m able to reproduce the scenario you are facing.
Root cause:
It’s due to Undeliverable email. These emails don’t hold any Sender or From data so it’s null. See this:
Solution:
This if condition will give you only undeliverable emails. item.Subject.StartsWith("Delivery has failed") AND item.From is Nothing and item.From is Nothing