How to use If Activity with Get Mail Activities

Hi. I want to do this. How can I do ?

If test@mail.com sent me an e-mail, do it process.
Else, notify me that there is no mail from test@mail.com

Use a flow chart and loop back to check if unread messages by filtering the required email.And then put a condition to forward with your process if the mail is received. Or else keep on looping.

1 Like

Hi @sufyant

Use condition as mail.from.address.ToString.contains(ā€œtest@mail.comā€)
Then process it or else print it as ā€œNo email found for this addressā€

Thanks
Ashwin.S

1 Like

in for each loop ?

Hi @sufyant

Yes in for each item

Thanks
Ashwin.S

1 Like

But I want to do this

If test@mail.com sent me mail, read my mail
Else just notify me

If I do as you say,it gives me more than one notification if more than one mail come

For example there are 3 mail in my mail but only 1 came from test@mail.com.
If I use this condition in the for each loop, robot will give me 2 notifications

Did you understand ?

Try this:

  • Using for each loop, loop through the mail messages .
  • Add an if condition ā€˜mail.Sender.Address.Contains(" test@mail.com")ā€™ in the loop
  • Maintain a flag say ā€˜blnMailFoundā€™ and set it to ā€˜trueā€™ if the condition is satisfied
  • Once all the mails are processed, outside the loop check the flag value and if its ā€˜falseā€™ (which means you havenā€™t received mail from specified sender), add notification
1 Like

hi @sufyant,
The condition is given by the other users are correct now you have top implement it with your logic suppose if the test@mail.com sent you mail then read it and proceed further if not then as per the if activity it will go to the else part where you have to defined what you want to do whether you want to print or keep into the log.
It is simple If else logic, if you get mail proceed further else do nothing
if im wrong in understanding then request you to kindly elaborate your problem

1 Like

Okay let me tell you what i want to do. I want to look all my emails and If I receive an email from test@mail.com, I would like to read the mail at test@mail.com and do the processing.If I have not received mail from test@mail.com, I want to notify to me

One more way of doing it would be -
Add a filter like ā€œ[From]=ā€˜[Mail address]ā€™ā€ in the Get Outlook Mail Messages activity.
This will filter out mails from the specified sender and check the count of the resulting collection. If its equal to ā€˜0ā€™ ,it means you donā€™t have mail from the specified sender and add notification.

1 Like

So how do I print this number on the screen?

The output of the ā€˜Get Outlook Mail Messagesā€™ activity would be a List of MailMessage. Create a list variable say ā€˜lstMailMessagesā€™ and assign it to the output. Check if(lstMailMessages.Count==0) ,if true then add notification.

Like that ?

2 Likes

Hi @sufyant

Perfect

Thanks
Ashwin S

The variable type should be ā€˜List Of(MailMessage)ā€™. Do a Ctrl+K in the output to create variable of the required type.

my variable is already like that

@Sowmyalaxmi_Kp @AshwinS2 But dont working

Hi @sufyant

try to loop them in for each item

Thanks
Ashwin S

how ?