UiPath Documentation
activities
latest
false
生産性を高めるアクティビティ
重要 :
このコンテンツの一部は機械翻訳によって処理されており、完全な翻訳を保証するものではありません。 新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。

メールのコード化されたオートメーション API

メール アクティビティ パッケージのコード化されたオートメーション API。

API を使用すると、[パッケージを管理] メニューで提供されているサービスにアクセスして操作することができます。これらの API は、コード化されたオートメーションを設計する際に使用できます。コード化されたオートメーションと、API を使用してそれらのオートメーションを設計する方法について詳しくは、こちらをご覧ください。

注:

[定義に移動] (F12) を使用すると、特定のサービスの UiPath API の定義にアクセスできます。コード化されたオートメーションを実装する場合は、直接公開されている API のみを使用することをお勧めします。サービスで直接公開されていないその他の API は、事前の通知なしに変更される場合があります。

オーバー ロード​

API には多くの場合、過剰な負荷があります。つまり、パラメーター オプションが異なる同じメソッドの複数のバージョンを提供します。 オーバー ロードすると、特定の要件に基づいて API の動作をカスタマイズできます。 たとえば、UI Automation API には、UI 要素が表示されるまでの最大時間を指定するタイムアウト パラメーターを受け入れるオーバー ロードが設定されている場合があります。

API をそれぞれのオーバーロードと共に使用することで、目的のオートメーション ロジックと動作を実現できます。

メールのコード化されたオートメーション API​

メールのコード化されたオートメーション API は、Mail.Activities パッケージの機能を補完し、完全なコーディング エクスペリエンスを提供します。このアプローチによって、カスタム アクションが促進され、再利用性がサポートされます。

まず、 mail オブジェクトを使用して、使用するメール サーバーに接続するインターフェイスを作成します。mail オブジェクトを使用すると、Imap、Pop3、Outlook、Smtp に接続できます。

接続すると、選択したメール サーバー用の特定のコード化されたオートメーション API が利用可能になります。たとえば、Outlook サーバーを使用している場合は、MarkRead や MoveMail などのコード化されたオートメーション API が利用可能になります。

次のインターフェイスを使用して特定のコード化されたオートメーション API にアクセスできます。

コード化されたオートメーション API説明
ImapIMAP に固有のコード化されたオートメーション API にアクセスするためのインターフェイスです。
Pop3POP3 に固有のコード化されたオートメーション API にアクセスするためのインターフェイスです。
SmtpSMTP に固有のコード化されたオートメーション API にアクセスするためのインターフェイスです。
OutlookOutlook に固有のコード化されたオートメーション API にアクセスするためのインターフェイスです。

API を使用する​

対応するサービスから API を呼び出すには、 service.APIの形式を使用します。 たとえば、 system.GetAssetします。

メールのコード化されたオートメーション API を使用する​

メールのコード化されたオートメーション API を使用するには、まず使用するメール サーバー (Imap、Pop3、Smtp、Outlook) に接続するインターフェイスを作成してから、そのインターフェイスで必要なコード化されたオートメーション API (interface.GetMessages() など) を呼び出します。

  1. アクティビティ パッケージをダウンロードします。
  2. コード化されたワークフローを作成します。
  3. mail サービスを呼び出し、Imap、Pop3、Outlook、Smtp のいずれかのサーバーに接続するインターフェイスを作成します。
  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 <ListString>{"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 <ListString>{"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;

        }
    }
}

このページは役に立ちましたか?

接続

ヘルプ リソース サポート

学習する UiPath アカデミー

質問する UiPath フォーラム

最新情報を取得