Get Newest Email (MicrosoftOffice365 Activity)

My bot is trying to log into a website (ADP) that SOMETIMES asks for extra verification so I’m automating that part as well. The bot clicks “send email verification code” on that website, then it checks Outlook for email using the “Get Newest Email” activity. The issue I’m having is that when there is only 1 unread email with the criteria (as expected there should be), it still gets marked as Read but Studio shows me the error: “Get Newest Email: Sequence contains no elements”. It’s like it’s seeing the email enough to mark it as read but not enough to actually get the data or something.
I have several of these verification emails in the inbox now, do to multiple attempts at this, so I’ve been trying different things and I’ve noticed that if I mark 2 or more of them as unread, the activity marks the first TWO of them as read but only successfully retrieves the data from the 2nd (which is an issue because it’s not the newest) and continues with the workflow.
Please help. Thanks in advance!!
Get Newest Email properties

Hi @JoKerCoder,

What you could try to do instead of using the “Get newest email” activity is to get all unread mails with the get mail list activity and filter them by the subject or sender. Usually the subject/sender from those 2FA mails are always the same.

I have never used this activity, but I have done “get the code from the verification email” just by using the Query property in the Get Mail (Office 365 - Classic) activity inside Microsoft Office 365 Scope.

Typically I tell it just to get the “top 1” email with a received date within the last 5 minutes, or 24 hours, or whatever is appropriate for your automation.

If it returns no emails, then it didn’t find the verification email that was sent. If it finds one, it returns the latest one.

For formulating your Query for the Get Mail activity, this is a great post: Microsoft Office 365 - Get Mail Activity Queries to filter returned emails

1 Like

Thanks, Paul. Got it working that way.

1 Like

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