Activities
latest
false
Mail APIs - Other latest
Banner background image
logo
Productivity Activities
Last updated Feb 16, 2024

Mail APIs

APIs allow you to access and interact with the services offered in the Manage Packages menu. You can use these APIs when you design coded automations. Visit Coded Automations to learn about coded automations and how to design them using APIs.
Note: Using Go to Definition (F12) allows you to access the definition of UiPath APIs for a certain service. We recommend relying only on the directly exposed APIs when you implement coded automations. Other APIs that are not directly exposed with a service are subject to change without prior notification.

Overloads

APIs often have overloads, which means they provide multiple versions of the same method with different parameter options. Overloads allow you to customize the behavior of the API based on your specific requirements. For example, a UI Automation API may have an overload that accepts a timeout parameter to specify the maximum time to wait for a UI element to appear before ending execution.

By using the APIs with their respective overloads, you can easily achieve your desired automation logic and behavior.

Mail APIs

The Mail APIs complement the capabilities of the Mail.Activities package, allowing you to have a full coding experience. This approach encourages custom actions, and supports reusability.

First, you create an interface that connects to the mail server that you want to use, through the mail object. The mail object allows you to connect to Imap, Pop3, Outlook, and Smtp.

Once connected, the specific APIs for your chosen mail server become available. For example, if you're using the Outlook server, APIs such as MarkRead and MoveMail become available.

You can use the following interfaces to access the specific APIs.
APIDescription
ImapThe interface through which you access the APIs specific to IMAP.
Pop3The interface through which you access the APIs specific to POP3.
SmtpThe interface through which you access the APIs specific to SMTP.
OutlookThe interface through which you access the APIs specific to Outlook.

Using APIs

Use the following format, to call an API from the corresponding service: service.API. For example, system.GetAsset.

Using Mail APIs

To use Mail APIs, you first create an interface that connects to the mail server that you want to use (Imap, Pop3, Smtp, Outlook), then call the desired APIs on this interface, such as interface.GetMessages().
  1. Download the activity package.
  2. Create a Coded Workflow.
  3. Call the mail service, and create an interface that connects to one of the following servers: Imap, Pop3, Outlook, Smtp.
  4. Call the desired APIs on the connection that you previously created.

Example

In the following example, you can see how you can send an email, configure the email, read, iterate, and move emails using Outlook.

using ProductivityTests.ObjectRepository;
using System;
using System.Collections.Generic;
using System.Data;
using UiPath.CodedWorkflows;
using UiPath.Core;
using UiPath.Core.Activities.Storage;
using UiPath.Mail.Activities.Api;
using UiPath.Orchestrator.Client.Models;
using UiPath.Testing;
using UiPath.Testing.Activities.TestData;
using UiPath.Testing.Activities.TestDataQueues.Enums;
using UiPath.Testing.Enums;
using UiPath.UIAutomationNext.API.Contracts;
using UiPath.UIAutomationNext.API.Models;
using UiPath.UIAutomationNext.Enums;
using UiPath.Mail;
using System.Net.Mail;
using System.Diagnostics;

namespace ProductivityTests
{
    public class MailExample : CodedWorkflow
    {
        [Workflow]
        public void Execute()
        {         

            //Send Simple Outlook Mail
            mail.Outlook().SendMail("firstname.lastname@organization.com","Test Subject","Body Message");
         
            //Configure your MailMessage and Send it
           SendMailOptions mailmessage = new SendMailOptions()
                .WithTo(new List<string>{"firstname.lastname@organization.com"})
                .WithSubject("A message through Coded Workflows")
                .WithBody(
                    "Hey,"
                    + Environment.NewLine
                    + "This message is sent by a robot built with Coded Workflows."
                    + Environment.NewLine
                    + Environment.NewLine 
                    + "Discover a sample code illustrating how to send, read, and move emails within the attachments."
                    + Environment.NewLine 
                    + "The mail package now features Coded Workflows support, introduced in the 1.22.0-preview Version released on December 04, 2023.");
           
            mailmessage.Attachments.Add("C:\\Users\\firstname.lastname\\Downloads\\CodedScreenshot.png");
            mailmessage.Attachments.Add("C:\\Users\\firstname.lastname\\Downloads\\MailExample.cs");
            mail.Outlook().SendMail(mailmessage);
                   
            // Read Mail Messages, iterate and move them
            GetOutlookMailOptions getMailOptions = new GetOutlookMailOptions()
                .WithFolder("Inbox")
                .WithOnlyUnreadMessages(true)
                .WithOrder(EOrderByDate.NewestFirst)
                .WithTop(50);
                                    
            var mails  = mail.Outlook().GetMessages(getMailOptions);
                       
            var counter =0;
            foreach(MailMessage mailMessage in mails)
            {
                counter++;
                Console.WriteLine(counter.ToString());
                Console.WriteLine(mailMessage.Subject);
                if (mailMessage.Subject.Contains("Coded Workflows"))
                {
                    //Move an email                    
                    mail.Outlook().MoveMail(mailMessage,"Demo");
                    Console.WriteLine("I found an email which contains Test");                   
                    
                }
                
            }
            //You can also define an object like this
            getMailOptions.WithFolder("Inbox");
            getMailOptions.WithOnlyUnreadMessages(true);
            getMailOptions.MailFolder ="Inbox";
            getMailOptions.OnlyUnreadMessages=true;
            getMailOptions.OrderByDate = EOrderByDate.NewestFirst;
            getMailOptions.Top=50;

        }
    }
}using ProductivityTests.ObjectRepository;
using System;
using System.Collections.Generic;
using System.Data;
using UiPath.CodedWorkflows;
using UiPath.Core;
using UiPath.Core.Activities.Storage;
using UiPath.Mail.Activities.Api;
using UiPath.Orchestrator.Client.Models;
using UiPath.Testing;
using UiPath.Testing.Activities.TestData;
using UiPath.Testing.Activities.TestDataQueues.Enums;
using UiPath.Testing.Enums;
using UiPath.UIAutomationNext.API.Contracts;
using UiPath.UIAutomationNext.API.Models;
using UiPath.UIAutomationNext.Enums;
using UiPath.Mail;
using System.Net.Mail;
using System.Diagnostics;

namespace ProductivityTests
{
    public class MailExample : CodedWorkflow
    {
        [Workflow]
        public void Execute()
        {         

            //Send Simple Outlook Mail
            mail.Outlook().SendMail("firstname.lastname@organization.com","Test Subject","Body Message");
         
            //Configure your MailMessage and Send it
           SendMailOptions mailmessage = new SendMailOptions()
                .WithTo(new List<string>{"firstname.lastname@organization.com"})
                .WithSubject("A message through Coded Workflows")
                .WithBody(
                    "Hey,"
                    + Environment.NewLine
                    + "This message is sent by a robot built with Coded Workflows."
                    + Environment.NewLine
                    + Environment.NewLine 
                    + "Discover a sample code illustrating how to send, read, and move emails within the attachments."
                    + Environment.NewLine 
                    + "The mail package now features Coded Workflows support, introduced in the 1.22.0-preview Version released on December 04, 2023.");
           
            mailmessage.Attachments.Add("C:\\Users\\firstname.lastname\\Downloads\\CodedScreenshot.png");
            mailmessage.Attachments.Add("C:\\Users\\firstname.lastname\\Downloads\\MailExample.cs");
            mail.Outlook().SendMail(mailmessage);
                   
            // Read Mail Messages, iterate and move them
            GetOutlookMailOptions getMailOptions = new GetOutlookMailOptions()
                .WithFolder("Inbox")
                .WithOnlyUnreadMessages(true)
                .WithOrder(EOrderByDate.NewestFirst)
                .WithTop(50);
                                    
            var mails  = mail.Outlook().GetMessages(getMailOptions);
                       
            var counter =0;
            foreach(MailMessage mailMessage in mails)
            {
                counter++;
                Console.WriteLine(counter.ToString());
                Console.WriteLine(mailMessage.Subject);
                if (mailMessage.Subject.Contains("Coded Workflows"))
                {
                    //Move an email                    
                    mail.Outlook().MoveMail(mailMessage,"Demo");
                    Console.WriteLine("I found an email which contains Test");                   
                    
                }
                
            }
            //You can also define an object like this
            getMailOptions.WithFolder("Inbox");
            getMailOptions.WithOnlyUnreadMessages(true);
            getMailOptions.MailFolder ="Inbox";
            getMailOptions.OnlyUnreadMessages=true;
            getMailOptions.OrderByDate = EOrderByDate.NewestFirst;
            getMailOptions.Top=50;

        }
    }
}
  • Overloads
  • Mail APIs
  • Using APIs
  • Using Mail APIs
  • Example
Support and Services icon
Get The Help You Need
UiPath Academy icon
Learning RPA - Automation Courses
UiPath Forum icon
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.