activities
latest
false
UiPath logo, featuring letters U and I in white
Productivity Activities
Last updated Nov 21, 2024

Manage Outlook Mails

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:

  1. Open Studio and create a new Process.
  2. Drag a Sequence container in the Workflow Designer.

    • Create the following variables:

      Variable Name

      Variable Type

      Default Value

      messages

      System.Collections.Generic.List<System.Net.Mail.MailMessage>

       

      junkMailFolder

      String

      "Junk Email"

      filter

      String

       

      sendTo

      String

       
  3. Drag an Assign activity inside the Sequence container.

    • Add the variable sendTo in the To field.
    • Add your email address in the Value field.

      Note: Make sure that the test.txt file is added to your project folder. This is used for sending you a testing email.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. Drag an If activity below the Write Line activity.

    • Add the expression messages.Count = 1 in the Condition field.
  10. Drag a Sequence container inside the Then field of the If activity.

    • Create the following variable:

      Variable Name

      Variable Type

      Default Value

      testMail

      System.Net.Mail.MailMessages

       
  11. 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.
  12. 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.
  13. 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:



  14. Run the process. A test email is sent to your mailbox, verified, and moved to the Junk Folder.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.