アクティビティ
最新
バナーの背景画像
生産性を高めるアクティビティ
最終更新日 2024年4月26日

メール 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 サーバーを使用している場合は、MarkReadMoveMail などの 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 サービスを呼び出し、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;

        }
    }
}

Was this page helpful?

サポートを受ける
RPA について学ぶ - オートメーション コース
UiPath コミュニティ フォーラム
UiPath ロゴ (白)
信頼とセキュリティ
© 2005-2024 UiPath. All rights reserved.