您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

教程:使用 Azure 逻辑应用创建自动化的基于审批的工作流Tutorial: Create automated approval-based workflows by using Azure Logic Apps

本教程介绍如何生成逻辑应用,以便自动完成基于审批的工作流。This tutorial shows how to build a logic app that automates an approval-based workflow. 具体说来,此逻辑应用处理通过 MailChimp 服务托管的邮件列表的订阅请求。Specifically, this logic app processes subscription requests for a mailing list that's managed by the MailChimp service. 此逻辑应用会监视电子邮件帐户中是否存在这些请求,发送这些请求进行审批,并向邮件列表添加批准的成员。This logic app monitors an email account for these requests, sends these requests for approval, and adds approved members to the mailing list.

在本教程中,你将了解如何执行以下操作:In this tutorial, you learn how to:

  • 创建空白逻辑应用。Create a blank logic app.
  • 添加一个触发器,用于监视电子邮件中的订阅请求。Add a trigger that monitors emails for subscription requests.
  • 添加一项操作,用于发送批准或拒绝这些请求的电子邮件。Add an action that sends emails for approving or rejecting these requests.
  • 添加一项操作,用于检查审批响应。Add a condition that checks the approval response.
  • 添加一项操作,用于向邮件列表添加批准的成员。Add an action that adds approved members to the mailing list.
  • 添加一个条件,用于检查这些成员是否已成功加入列表。Add a condition that checks whether these members successfully joined the list.
  • 添加一项操作,其发送的电子邮件用于确认这些成员是否已成功加入列表。Add an action that sends emails confirming whether these members successfully joined the list.

完成后,逻辑应用看起来大致与以下工作流类似:When you're done, your logic app looks like this workflow at a high level:

完成的高级逻辑应用概述

必备条件Prerequisites

  • Azure 订阅。An Azure subscription. 如果你没有 Azure 订阅,请在开始之前注册一个免费 Azure 帐户If you don't have a subscription, sign up for a free Azure account before you begin.

  • 一个 MailChimp 帐户,其中包含名为“test-members-ML”的列表,供逻辑应用在其中为批准的成员添加电子邮件地址。A MailChimp account that contains a list named "test-members-ML" where your logic app can add email addresses for approved members. 如果没有帐户,请注册免费帐户,然后了解如何创建 MailChimp 列表If you don't have an account, sign up for a free account, and then learn how to create a MailChimp list.

  • Office 365 Outlook 或 Outlook.com 中的电子邮件帐户,支持审批工作流。An email account in Office 365 Outlook or Outlook.com, which supports approval workflows. 本文使用 Office 365 Outlook。This article uses Office 365 Outlook. 如果使用其他电子邮件帐户,则常规步骤保持不变,但 UI 显示可能稍有不同。If you use a different email account, the general steps stay the same, but your UI might appear slightly different.

登录到 Azure 门户Sign in to the Azure portal

使用 Azure 帐户凭据登录到 Azure 门户Sign in to the Azure portal with your Azure account credentials.

创建逻辑应用Create your logic app

  1. 在 Azure 主菜单中,依次选择“创建资源” > “集成” > “逻辑应用”。 From the main Azure menu, select Create a resource > Integration > Logic App.

    创建新的逻辑应用资源

  2. 在“创建逻辑应用”下,提供有关逻辑应用的信息,如下所示。 Under Create logic app, provide this information about your logic app as shown and described. 完成操作后,选择“创建” 。When you're done, select Create.

    提供有关逻辑应用的信息

    propertiesProperty Value 说明Description
    名称Name LA-MailingListLA-MailingList 逻辑应用的名称,只能包含字母、数字、连字符 (-)、下划线 (_)、括号(())和句点 (.)。Your logic app's name, which can contain only letters, numbers, hyphens (-), underscores (_), parentheses ((, )), and periods (.). 此示例使用“LA-MailingList”。This example uses "LA-MailingList".
    订阅Subscription <your-Azure-subscription-name><your-Azure-subscription-name> Azure 订阅名称Your Azure subscription name
    资源组Resource group LA-MailingList-RGLA-MailingList-RG 用于组织相关资源的 Azure 资源组的名称。The name for the Azure resource group, which is used to organize related resources. 此示例使用“LA-MailingList-RG”。This example uses "LA-MailingList-RG".
    位置Location 美国西部West US 用于存储逻辑应用信息的区域。TThe region where to store your logic app information. 此示例使用“美国西部”。This example uses "West US".
    Log AnalyticsLog Analytics 关闭Off 对于诊断日志记录,请保留“关闭”设置。 Keep the Off setting for diagnostic logging.
  3. 在 Azure 部署你的应用后,在 Azure 工具栏上,选择“通知” > “转到资源” ,查看你部署的逻辑应用。After Azure deploys your app, on the Azure toolbar, select Notifications > Go to resource for your deployed logic app.

    转到新的逻辑应用资源

    或者,可以通过在搜索框中键入名称来查找和选择逻辑应用。Or, you can find and select your logic app by typing the name in the search box.

    逻辑应用设计器打开并显示一个包含简介视频以及常用触发器和逻辑应用模式的页面。The Logic Apps Designer opens and shows a page with an introduction video and commonly used triggers and logic app patterns. 在“模板”下选择“空白逻辑应用”。Under Templates, select Blank Logic App.

    选择空白逻辑应用模板

接下来,请添加一个触发器,侦听包含订阅请求的传入电子邮件。Next, add a trigger that listens for incoming emails with subscription requests. 每个逻辑应用都必须从触发器开始,在发生特定事件或新数据符合特定条件的情况下触发。Each logic app has to start with a trigger, which fires when a specific event happens or when new data meets a specific condition. 有关详细信息,请参阅创建第一个逻辑应用For more information, see Create your first logic app.

添加用于监视电子邮件的触发器Add trigger to monitor emails

  1. 在逻辑应用设计器上的搜索框中,输入 when email arrives 作为筛选器。On the Logic App Designer, in the search box, enter when email arrives as your filter. 从“触发器”列表中,为电子邮件提供商选择“收到新电子邮件时”触发器。 From the Triggers list, select the When a new email arrives trigger for your email provider.

    此示例使用 Office 365 Outlook 触发器:This example uses the Office 365 Outlook trigger:

    为电子邮件提供商选择“收到新电子邮件时”触发器

    • 对于 Azure 工作或学校帐户,请选择“Office 365 Outlook”。For Azure work or school accounts, select Office 365 Outlook.
    • 对于个人 Microsoft 帐户,请选择“Outlook.com”。For personal Microsoft accounts, select Outlook.com.
  2. 如果系统要求,请使用凭据登录电子邮件帐户,这样逻辑应用就可以创建到该电子邮件帐户的连接了。If prompted, sign in to your email account with your credentials so that Logic Apps can create a connection to your email account.

  3. 在触发器中,提供查看所有新电子邮件的条件。In the trigger, provide the criteria for checking all new email.

    1. 指定用于检查电子邮件的文件夹、时间间隔和频率。Specify the folder, interval, and frequency for checking emails.

      指定用于检查邮件的文件夹、时间间隔和频率

      propertiesProperty Value 说明Description
      文件夹Folder Inbox 要监视的电子邮件文件夹The email folder to monitor
      间隔 Interval 1 在两次检查之间需等待的时间间隔数The number of intervals to wait between checks
      频率Frequency Hour 用于定期触发的时间单位The unit of time to use for the recurrence
    2. 现在,为触发器添加另一属性,这样就可以在电子邮件主题行中进行筛选。Now add another property to the trigger so that you can filter on email subject line. 打开“添加新参数”列表,选择“主题筛选器”属性。 Open the Add new parameter list, and select the Subject Filter property.

      将“主题筛选器”属性添加到触发器

      有关此触发器的属性的详细信息,请参阅 Office 365 Outlook 连接器参考Outlook.com 连接器参考For more information about this trigger's properties, see the Office 365 Outlook connector reference or the Outlook.com connector reference.

    3. 当属性显示在触发器中以后,请输入此文本:subscribe-test-members-MLAfter the property appears in the trigger, enter this text: subscribe-test-members-ML

      为“主题筛选器”属性输入文本

  4. 若要立即隐藏触发器的详细信息,请单击触发器的标题栏。To hide the trigger's details for now, click the trigger's title bar.

    折叠形状即可隐藏详细信息

  5. 保存逻辑应用。Save your logic app. 在设计器工具栏上,选择“保存” 。On the designer toolbar, select Save.

逻辑应用现已生成,但除了检查传入电子邮件,不能执行任何操作。Your logic app is now live but doesn't do anything other than check your incoming email. 因此,请添加一项在触发器触发时进行响应的操作。So, add an action that responds when the trigger fires.

发送批准电子邮件Send approval email

有了触发器以后,即可添加一项操作,以便发送批准或拒绝请求的电子邮件。Now that you have a trigger, add an action that sends an email to approve or reject the request.

  1. 在触发器下,选择“新建步骤”。 Under the trigger, select New step.

  2. 在“选择操作” 下的搜索框中,输入 approval 作为筛选器。Under Choose an action, in the search box, enter approval as your filter. 从操作列表中,为电子邮件提供商选择“发送审批电子邮件”操作。 From the actions list, select the Send approval email action for your email provider.

    此示例使用 Office 365 Outlook 操作:This example uses the Office 365 Outlook action:

    选择“发送审批电子邮件”操作

  3. 根据以下说明提供有关此操作的信息:Provide the information about this action as described:

    “发送审批电子邮件”操作的属性

    propertiesProperty Value 说明Description
    收件人To <your-email-address><your-email-address> 审批者的电子邮件地址。The approver's email address. 可以使用自己的地址进行测试。For testing purposes, you can use your own address. 此示例使用虚构的“sophia.owen@fabrikam.com”电子邮件地址。This example uses the fictional "sophia.owen@fabrikam.com" email address.
    主题Subject Approve member request for test-members-ML 一个描述性的电子邮件主题A descriptive email subject
    用户选项User Options Approve, Reject 审批者可以选择的响应选项。The response options that the approver can select. 默认情况下,审批者可以选择“批准”或“拒绝”作为其响应。By default, the approver can select either "Approve" or "Reject" as their response.

    现在,请忽略在单击特定编辑框时会显示的动态内容列表。For now, ignore the dynamic content list that appears when you click inside specific edit boxes. 可以通过此列表选择以前的操作提供的可用输出,这些输出可以在工作流中用作输入。This list lets you select available output from previous actions that you can use as inputs in your workflow.

    有关此操作的属性的详细信息,请参阅 Office 365 Outlook 连接器参考Outlook.com 连接器参考For more information about this action's properties, see the Office 365 Outlook connector reference or the Outlook.com connector reference.

  4. 保存逻辑应用。Save your logic app.

接下来,请添加一个条件,用于检查审批者选定的响应。Next, add a condition to check the approver's selected response.

检查审批响应Check approval response

  1. 在“发送审批电子邮件”操作下,选择“新建步骤”。 Under the Send approval email action, select New step".

  2. 在“选择操作”下,选择“内置”。 Under Choose an action, select Built-in. 在搜索框中,输入 condition 作为筛选器。In the search box, enter condition as your filter. 从操作列表中选择“条件”操作。 From the actions list, select the Condition action.

    查找并选择“条件”操作

  3. 重命名此条件,并提供更好的说明。Rename the condition with a better description.

    1. 在条件的标题栏中,选择省略号 ( ... ) 按钮 >“重命名”。 On the condition's title bar, select the ellipses (...) button > Rename.

      重命名条件的说明

    2. 重命名条件并提供以下说明:If request approvedRename your condition with this description: If request approved

  4. 生成一个条件,用于检查审批者是否选择了“批准”。 Build a condition that checks whether the approver selected Approve.

    1. 在条件中,单击条件左侧的“选择值”框。 In the condition, click inside the Choose a value box on the condition's left side.

    2. 从显示的动态内容列表中的“发送审批电子邮件”下选择 SelectedOption 属性。 From the dynamic content list that appears, under Send approval email, select the SelectedOption property.

      从动态内容列表中,选择“SelectedOption”

    3. 在中间的比较框中,选择“等于” 运算符。In the middle comparison box, select the is equal to operator.

    4. 在条件右侧的“选择值”框中输入此文本:Approve In the Choose a value box on the condition's right side, enter this text: Approve

      完成后,条件如以下示例所示:When you're done, the condition looks like this example:

      已批准示例的完成条件

  5. 保存逻辑应用。Save your logic app.

接下来,请指定一项操作,供逻辑应用在审批者批准请求的情况下执行。Next, specify the action that your logic app performs when the reviewer approves the request.

将成员添加到 MailChimp 列表Add member to MailChimp list

现在请添加一项操作,用于将批准的成员添加到邮件列表。Now add an action that adds the approved member to your mailing list.

  1. 在条件的 If true 分支中,选择“添加操作”。 In the condition's If true branch, select Add an action.

  2. 在“选择操作” 下,输入 mailchimp 作为筛选器,然后选择“将成员添加到列表”操作。 Under Choose an action, enter mailchimp as your filter, and select the Add member to list action.

    选择“将成员添加到列表”操作

  3. 如果系统提示你访问 MailChimp 帐户,请使用 MailChimp 凭据登录。If you're prompted for access to your MailChimp account, sign in with your MailChimp credentials.

  4. 提供有关此操作的信息,如下所示:Provide information about this action as shown and described here:

    为“将成员添加到列表”提供信息

    propertiesProperty 必选Required Value 说明Description
    列表 IDList Id Yes test-members-ML MailChimp 邮件列表的名称。The name for your MailChimp mailing list. 此示例使用“test-members-ML”。This example uses "test-members-ML".
    StatusStatus Yes subscribed 选择新成员的订阅状态。Select the subscription status for the new member. 本示例使用“subscribed”。This example uses "subscribed".

    有关详细信息,请参阅 Manage subscribers with the MailChimp API(使用 MailChimp API 管理订户)。For more information, see Manage subscribers with the MailChimp API.

    电子邮件地址Email Address Yes <new-member-email-address><new-member-email-address> 在动态内容列表的“收到新电子邮件时”下选择“发件人”,以便传入新成员的电子邮件地址。 From the dynamic content list, select From under When a new mail arrives, which passes in the email address for the new member.

    有关此操作的属性的详细信息,请参阅 MailChimp 连接器参考For more information about this action's properties, see the MailChimp connector reference.

  5. 保存逻辑应用。Save your logic app.

接下来,请添加一个条件,以便检查新成员是否已成功加入邮件列表。Next, add a condition so that you can check whether the new member successfully joined your mailing list. 这样一来,逻辑应用即可通知你该操作是成功还是失败。That way, your logic app notifies you whether this operation succeeds or fails.

检查操作是成功还是失败Check for success or failure

  1. If true 分支的“将成员添加到列表”操作下, 选择“添加操作” 。In the If true branch, under the Add member to list action, select Add an action.

  2. 在“选择操作”下,选择“内置”。 Under Choose an action, select Built-in. 在搜索框中,输入 condition 作为筛选器。In the search box, enter condition as your filter. 在操作列表中选择“条件”。 From the actions list, select Condition.

  3. 重命名条件并提供以下说明:If add member succeededRename the condition with this description: If add member succeeded

  4. 生成一个条件,用于检查批准的成员在加入邮件列表时是成功还是失败:Build a condition that checks whether the approved member succeeds or fails in joining your mailing list:

    1. 在条件中,单击条件左侧的“选择值”框。 In the condition, click inside the Choose a value box, which is on the condition's left side. 在动态内容列表的“将成员添加到列表”下,选择“状态”属性。 From the dynamic content list, under Add member to list, select the Status property.

      例如,你的条件如以下示例所示:For example, your condition looks like this example:

      在“将成员添加到列表”下,选择“状态”

    2. 在中间的比较框中,选择“等于” 运算符。In the middle comparison box, select the is equal to operator.

    3. 在条件右侧的“选择值”框中输入此文本:subscribed In the Choose a value box on the condition's right side, enter this text: subscribed

      完成后,条件如以下示例所示:When you're done, the condition looks like this example:

      已订阅示例的完成条件

接下来,请设置电子邮件,以便在批准的成员成功加入或无法加入邮件列表时发送。Next, set up the emails to send when the approved member succeeds or fails in joining your mailing list.

在添加了成员的情况下发送电子邮件Send email if member added

  1. 在“如果添加成员成功”条件的 If true 分支中,选择“添加操作”。 Under the If add member succeeded condition, in the If true branch, select Add an action.

    在“If true”分支中,选择“添加操作”

  2. 在“选择操作” 下的搜索框中,输入 outlook send email 作为筛选器,然后选择“发送电子邮件”操作。 Under Choose an action, in the search box, enter outlook send email as your filter, and select the Send an email action.

    添加“发送电子邮件”操作

  3. 重命名操作并提供以下说明:Send email on successRename the action with this description: Send email on success

  4. 提供此操作的信息,如下所示:Provide information for this action as shown and described:

    提供成功电子邮件的信息

    propertiesProperty 必选Required Value 说明Description
    收件人To Yes <your-email-address><your-email-address> 一个电子邮件地址,可向其发送成功电子邮件。The email address for where to send the success email. 为进行测试,可以使用自己的电子邮件地址。For testing purposes, you can use your own email address.
    主题Subject Yes <subject-for-success-email><subject-for-success-email> 成功电子邮件的主题。The subject for the success email. 对于本教程,请输入以下文本:For this tutorial, enter this text:

    Success! Member added to "test-members-ML":

    在动态内容列表的“将成员添加到列表”下,选择“电子邮件地址”属性。 From the dynamic content list, under Add member to list, select the Email Address property.

    正文Body Yes <body-for-success-email><body-for-success-email> 成功电子邮件的正文内容。The body content for the success email. 对于本教程,请输入以下文本:For this tutorial, enter this text:

    New member has joined "test-members-ML":

    在动态内容列表中,选择“电子邮件地址”属性。 From the dynamic content list, select the Email Address property.

    在下一行中,输入此文本:Member opt-in status:On the next row, enter this text: Member opt-in status:

    在动态内容列表的“将成员添加到列表”下,选择“状态”属性。 From the dynamic content list, under Add member to list, select the Status property.

  5. 保存逻辑应用。Save your logic app.

在添加不了成员的情况下发送电子邮件Send email if member not added

  1. 在“如果添加成员成功”条件的 If false 分支中,选择“添加操作”。 Under the If add member succeeded condition, in the If false branch, select Add an action.

    在“If false”分支中,选择“添加操作”

  2. 在“选择操作” 下的搜索框中,输入 outlook send email 作为筛选器,然后选择“发送电子邮件”操作。 Under Choose an action, in the search box, enter outlook send email as your filter, and select the Send an email action.

    为“发送电子邮件”添加操作

  3. 重命名操作并提供以下说明:Send email on failureRename the action with this description: Send email on failure

  4. 提供有关此操作的信息,如下所示:Provide information about this action as shown and described here:

    提供失败电子邮件的信息

    propertiesProperty 必选Required Value 说明Description
    收件人To Yes <your-email-address><your-email-address> 一个电子邮件地址,可向其发送失败电子邮件。The email address for where to send the failure email. 为进行测试,可以使用自己的电子邮件地址。For testing purposes, you can use your own email address.
    主题Subject Yes <subject-for-failure-email><subject-for-failure-email> 失败电子邮件的主题。The subject for the failure email. 对于本教程,请输入以下文本:For this tutorial, enter this text:

    Failed, member not added to "test-members-ML":

    在动态内容列表的“将成员添加到列表”下,选择“电子邮件地址”属性。 From the dynamic content list, under Add member to list, select the Email Address property.

    正文Body Yes <body-for-failure-email><body-for-failure-email> 失败电子邮件的正文内容。The body content for the failure email. 对于本教程,请输入以下文本:For this tutorial, enter this text:

    Member might already exist. Check your MailChimp account.

  5. 保存逻辑应用。Save your logic app.

接下来测试逻辑应用,该应用现在看起来类似于以下示例:Next, test your logic app, which now looks similar to this example:

完成的逻辑应用工作流示例

运行逻辑应用Run your logic app

  1. 向自己发送一封加入邮件列表的电子邮件请求。Send yourself an email request to join your mailing list. 等待请求显示在收件箱中。Wait for the request to appear in your inbox.

  2. 若要手动启动逻辑应用,请在设计器工具栏中选择“运行” 。To manually start your logic app, on the designer toolbar bar, select Run.

    如果电子邮件的主题与触发器的主题筛选器匹配,逻辑应用会向你发送审批订阅请求的电子邮件。If your email has a subject that matches the trigger's subject filter, your logic app sends you email to approve the subscription request.

  3. 在审批电子邮件中,选择“批准” 。In the approval email, select Approve.

  4. 如果订户的电子邮件地址在邮件列表中不存在,逻辑应用会添加该人的电子邮件地址并向你发送一封电子邮件,如以下示例所示:If the subscriber's email address doesn't exist on your mailing list, your logic app adds that person's email address and sends you an email like this example:

    示例电子邮件 - 成功订阅

    如果逻辑应用无法添加订户,你会收到一封电子邮件,如下示例所示:If your logic app can't add the subscriber, you get an email like this example:

    示例电子邮件 - 失败订阅

    如果没有收到任何电子邮件,请检查电子邮件的垃圾邮件文件夹。If you don't get any emails, check your email's junk folder. 垃圾电子邮件筛选器可能会将这些类型的邮件重定向。Your email junk filter might redirect these kinds of mails. 否则,如果不确定逻辑应用是否正常运行,请参阅逻辑应用故障排除Otherwise, if you're unsure that your logic app ran correctly, see Troubleshoot your logic app.

祝贺!你现在已创建并运行可以跨 Azure、Microsoft 服务和其他 SaaS 应用集成信息的逻辑应用。Congratulations, you've now created and run a logic app that integrates information across Azure, Microsoft services, and other SaaS apps.

清理资源Clean up resources

不再需要示例逻辑应用时,请删除包含该逻辑应用和相关资源的资源组。When you no longer need the sample logic app, delete the resource group that contains your logic app and related resources.

  1. 在 Azure 主菜单中转到“资源组”,然后选择逻辑应用的资源组。 On the main Azure menu, go to Resource groups, and select the resource group for your logic app.

  2. 在资源组菜单中,选择“概述” > “删除资源组”。 On the resource group menu, select Overview > Delete resource group.

    “概览”>“删除资源组”

  3. 输入资源组名称作为确认,然后选择“删除”。 Enter the resource group name as confirmation, and select Delete.

后续步骤Next steps

本教程介绍了如何创建逻辑应用,以便管理邮件列表请求的审批。In this tutorial, you created a logic app that manages approvals for mailing list requests. 现在,请了解如何集成 Azure 存储和 Azure Functions 之类的 Azure 服务,以便生成处理和存储电子邮件附件的逻辑应用。Now, learn how to build a logic app that processes and stores email attachments by integrating Azure services, such as Azure Storage and Azure Functions.