活动
最新
False
横幅背景图像
生产力活动
上次更新日期 2024年4月26日

邮件 API

API 允许您访问“管理包”菜单中提供的服务并与之交互。 您可以在设计编码自动化时使用这些 API。 请访问编码自动化,了解编码自动化以及如何使用 API 进行设计。
注意:使用“转到定义”(F12) 允许您访问特定服务的 UiPath API 定义。我们建议在实施编码自动化时仅依赖直接公开的 API。未直接与服务一起公开的其他 API 如有更改,恕不另行通知。

重载

API 通常具有重载,这意味着它们为同一方法的多个版本提供不同的参数选项。重载允许您根据特定要求自定义 API 的行为。例如,用户界面自动化 API 可能具有接受超时参数的重载,以指定在结束执行之前等待用户界面元素出现的最长时间。

通过使用具有各自重载的 API,您可以轻松实现所需的自动化逻辑和行为。

邮件 API

邮件 API 补充了 Mail.Activities 包的功能,让您获得完整的编码体验。 此方法鼓励自定义操作,并支持可重用性。

首先,创建一个通过mail对象连接到您要使用的邮件服务器的接口。 mail对象允许您连接到 Imap、Pop3、Outlook 和 SMTP。

连接后,即可使用所选邮件服务器的特定 API。 例如,如果您使用的是 Outlook Server,则可以使用“ MarkRead”和“ MoveMail ”等 API。

您可以使用以下接口来访问特定 API。
API描述
Imap用于访问特定于IMAP的 API 的接口。
Pop3用于访问特定于POP3的 API 的接口。
Smtp用于访问特定于SMTP的 API 的接口。
Outlook用于访问特定于Outlook的 API 的界面。

使用 API

使用以下格式从相应的服务调用 API: service.API。 例如 system.GetAsset

使用邮件 API

要使用邮件 API,请首先创建一个连接到您要使用的邮件服务器(Imap、Pop3、SMTP、Outlook)的接口,然后在此接口上调用所需的 API,例如interface.GetMessages()
  1. 下载活动包。
  2. 创建编码工作流
  3. 调用mail服务,并创建连接到以下服务器之一的接口: ImapPop3OutlookSmtp
  4. 在先前创建的连接上调用所需的 API。

示例

在以下示例中,您可以看到如何使用 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;

        }
    }
}
  • 重载
  • 邮件 API
  • 使用 API
  • 使用邮件 API
  • 示例

此页面是否有帮助?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath 白色徽标
信任与安全
© 2005-2024 UiPath. All rights reserved.