The example below explains how to create a workflow that automatically sends a test email, identifies it, and moves it in the Junk folder. It presents activities such as Send Outlook Mail Message, Get Outlook Mail Messages, and Move Outlook Mail Message. You can find these activities in the UiPath.Mail.Activities package.
This is how the automation process can be built:
- Open Studio and create a new Process.
- Drag a Sequence container in the Workflow Designer.
- Create the following variables:
Variable Name | Variable Type | Default Value |
---|---|---|
| System.Collections.Generic.List<System.Net.Mail.MailMessage> | |
| String | "Junk Email" |
| String | |
| String |
- Drag an Assign activity inside the Sequence container.
- Add the variable
sendTo
in the To field. - Add your email address in the Value field.
- Add the variable
Note:
Make sure that the
test.txt
file is added to your project folder. This is used for sending you a testing email.
- Drag a Send Outlook Mail Message activity below the Assign activity.
- Add the variable
sendTo
in the To field. - Add the expression
"This is a test mail for me"
in the Subject field. - Add the expression
"Lorem ipsum"
in the Body field.
- Add the variable
- Drag a Delay activity below the Send Outlook Mail Message activity.
- In the Properties panel, add the value
00:00:10
in the Duration field.
- In the Properties panel, add the value
- Drag an Assign activity below the Delay activity.
- Add the variable
filter
in the To field. - Add the expression
"[Subject]='This is a test mail for me' AND [Received] >= '1/17/2019'"
in the Value field.
- Add the variable
- Drag a Get Outlook Mail Message activity below the Assign activity.
- In the Properties panel, add the variable
filter
in the Filter field. - Add the variable
messages
in the Messages field.
- In the Properties panel, add the variable
- Drag a Write Line activity below the Get Outlook Mail Message activity.
- Add the expression
String.Format("# of test mails found: {0}", messages.Count)
in the Text field.
- Add the expression
- Drag an If activity below the Write Line activity.
- Add the expression
messages.Count = 1
in the Condition field.
- Add the expression
- Drag a Sequence container inside the Then field of the If activity.
- Create the following variable:
Variable Name | Variable Type | Default Value |
---|---|---|
| System.Net.Mail.MailMessages |
- Drag an Assign activity inside the Sequence container.
- Add the variable
testMail
in the To field. - Add the expression
messages(0)
in the Value field.
- Drag a Move Outlook Mail Message below the Assign activity.
- Add the variable
testMail
in the Mail Message field. - Add the variable
junkMailFolder
in the Mail Folder field.
- Drag a Write Line activity inside the Else field of the If activity.
- Add the expression
"We're getting more test mails than expected. Check your Inbox and perform a cleanup before trying this sample again."
in the Text field.
This is how your workflow should look:


- Run the process. A test email is sent to your mailbox, verified, and moved to the Junk Folder.
Updated 5 months ago