在 Office 365 中通过电子邮件发送可操作邮件Send an actionable message via email in Office 365

支持的方案Supported scenarios

在以下方案中支持通过电子邮件发送可操作邮件。Sending actionable messages via email is supported in the following scenarios.

  • 收件人必须是个人,不能是组。The recipient must be an individual, not a group.
  • 收件人必须在邮件上可见。The recipient must be visible on the message. 不要将收件人置于“密件抄送”字段中。Do not put the recipient in the BCC field.
  • 收件人必须在 Outlook.com 或 Office 365 的 Exchange Online 上具有邮箱。The recipient must have a mailbox on Outlook.com or Exchange Online in Office 365.

创建可操作邮件卡片Create an actionable message card

我们从创建可操作邮件卡开始。我们将从简单的内容开始,即一个包含 Action.Http 操作和 Action.OpenUrl 操作的简单卡片。我们将使用卡片样本设计此卡片。Let's start by creating an actionable message card. We'll start with something simple, just a basic card with an Action.Http action and an Action.OpenUrl action. We'll use the Card Playground to design the card.

重要

本主题中的示例卡片标记省略了 originator 属性。The sample card markup in this topic omits the originator property. 这适用于收件人与发件人是同一人的测试场景。This works in a testing scenario, where the recipient is the same as the sender. 向其他人发送可操作邮件时,必须将 originator 属性设置为可操作电子邮件开发人员仪表板生成的有效提供程序 ID。When sending actionable messages to anyone else, the originator property must be set to a valid provider ID generated by the Actionable Email Developer Dashboard. 如果向其他人发送可操作邮件时将此属性留空,将会导致卡片被删除。Leaving this property empty when sending to others results in the card being removed.

转到卡片样本,并粘贴以下 JSON:Go to the Card Playground and paste in the following JSON:

{
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "TextBlock",
      "text": "Visit the Outlook Dev Portal",
      "size": "large"
    },
    {
        "type": "TextBlock",
        "text": "Click **Learn More** to learn more about Actionable Messages!"
    },
    {
      "type": "Input.Text",
      "id": "feedbackText",
      "placeholder": "Let us know what you think about Actionable Messages"
    }
  ],
  "actions": [
    {
      "type": "Action.Http",
      "title": "Send Feedback",
      "method": "POST",
      "url": "https://...",
      "body": "{{feedbackText.value}}"
    },
    {
      "type": "Action.OpenUrl",
      "title": "Learn More",
      "url": "https://docs.microsoft.com/outlook/actionable-messages"
    }
  ]
}

请在样本中随意使用此简单示例进行试验。可参阅自适应卡片参考了解可用字段的详细信息。制作出满意的卡片后,就可以发送了。Feel free to experiment with this simple example in the playground. You can see the adaptive card reference for details on the available fields. Once you have a card you're happy with, you can move on to sending it.

通过电子邮件发送可操作邮件Sending actionable messages via email

重要

可以通过使用卡片样本来设计和测试可操作邮件,以便向自己发送可操作邮件。此外,还可以使用 Office 365 SMTP 服务器向自己发送可操作邮件。在使用可操作邮件开发人员仪表板注册之前,将无法向任何其他用户发送可操作邮件。You can design and test actionable messages by using the Card Playground, which allows you to send actionable messages to yourself. You can also send actionable messages to yourself using the Office 365 SMTP server. You will be unable to send actionable messages to any other user until you have registered using the actionable messages developer dashboard.

若要在电子邮件中嵌入可操作邮件卡,需要将该卡片封装到 <script> 标记。然后将 <script> 标记插入电子邮件 HTML 正文的 <head> 中。To embed an actionable message card in an email message, we need to wrap the card in a <script> tag. The <script> tag is then inserted into the <head> of the email's HTML body.

备注

由于 JSON 卡片必须包装在 <script> 标记中,可操作电子邮件的正文必须为 HTML。不支持纯文本邮件。Because the card JSON must be wrapped in a <script> tag, the body of the actionable message email MUST be HTML. Plain-text messages are not supported.

  1. 添加 hideOriginalBody 属性,以控制对电子邮件正文的处理。在此示例中我们将该属性设置为 true,确保不显示正文。Add the hideOriginalBody attribute to control what happens with the body of the email. In this case we'll set the attribute to true so that the body will not be shown.

    {
      "type": "AdaptiveCard",
      "version": "1.0",
      "hideOriginalBody": true,
      "body": [
        {
          "type": "TextBlock",
          "text": "Visit the Outlook Dev Portal",
          "size": "large"
        },
        {
            "type": "TextBlock",
            "text": "Click **Learn More** to learn more about Actionable Messages!"
        },
        {
          "type": "Input.Text",
          "id": "feedbackText",
          "placeholder": "Let us know what you think about Actionable Messages"
        }
      ],
      "actions": [
        {
          "type": "Action.Http",
          "title": "Send Feedback",
          "method": "POST",
          "url": "https://...",
          "body": "{{feedbackText.value}}"
        },
        {
          "type": "Action.OpenUrl",
          "title": "Learn More",
          "url": "https://docs.microsoft.com/outlook/actionable-messages"
        }
      ]
    }
    
  2. 将生成的 JSON 封装到 application/adaptivecard+json 类型的 <script> 标记中。Wrap the resulting JSON in a <script> tag of type application/adaptivecard+json.

    备注

    如果正在使用旧版邮件卡片格式而不是自适应卡片格式,<script> 标记类型必须为 application/ld+jsonIf you are using the legacy message card format rather than the Adaptive card format, the <script> tag type MUST be application/ld+json.

    <script type="application/adaptivecard+json">{
      "type": "AdaptiveCard",
      "version": "1.0",
      "hideOriginalBody": true,
      "body": [
        {
          "type": "TextBlock",
          "text": "Visit the Outlook Dev Portal",
          "size": "large"
        },
        {
            "type": "TextBlock",
            "text": "Click **Learn More** to learn more about Actionable Messages!"
        },
        {
          "type": "Input.Text",
          "id": "feedbackText",
          "placeholder": "Let us know what you think about Actionable Messages"
        }
      ],
      "actions": [
        {
          "type": "Action.Http",
          "title": "Send Feedback",
          "method": "POST",
          "url": "https://...",
          "body": "{{feedbackText.value}}"
        },
        {
          "type": "Action.OpenUrl",
          "title": "Learn More",
          "url": "https://docs.microsoft.com/outlook/actionable-messages"
        }
      ]
    }
    </script>
    
  3. 生成 HTML 文档以显示电子邮件正文,并将 <script> 标记包含在 <head> 中。Generate an HTML document to represent the email body and include the <script> tag in the <head>.

    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <script type="application/adaptivecard+json">{
        "type": "AdaptiveCard",
        "version": "1.0",
        "hideOriginalBody": true,
        "body": [
          {
            "type": "TextBlock",
            "text": "Visit the Outlook Dev Portal",
            "size": "large"
          },
          {
            "type": "TextBlock",
            "text": "Click **Learn More** to learn more about Actionable Messages!"
          },
          {
            "type": "Input.Text",
            "id": "feedbackText",
            "placeholder": "Let us know what you think about Actionable Messages"
          }
        ],
        "actions": [
          {
            "type": "Action.Http",
            "title": "Send Feedback",
            "method": "POST",
            "url": "https://...",
            "body": "{{feedbackText.value}}"
          },
          {
            "type": "Action.OpenUrl",
            "title": "Learn More",
            "url": "https://docs.microsoft.com/outlook/actionable-messages"
          }
        ]
      }
      </script>
    </head>
    <body>
    Visit the <a href="https://docs.microsoft.com/outlook/actionable-messages">Outlook Dev Portal</a> to learn more about Actionable Messages.
    </body>
    </html>
    
  4. 通过 SMTP 发送将 HTML 作为正文的电子邮件。Send a message via SMTP with the HTML as the body.

发送邮件Sending the message

有关发送邮件的示例,请参阅下列内容。For examples of sending messages, see the following.

执行操作Perform actions

有关执行操作的示例,请参阅以下部分。For examples of performing actions, see the following.

  • Hello 可操作邮件:包含一键式 Azure 部署按钮的示例项目。Hello Actionable Messages: A sample project with one-click button Azure deployment. 此示例是简单的端到端可操作邮件解决方案,能够在 10 分钟内正常运行,可以参考它生成生产操作终结点。This sample is a simple end-to-end actionable message solution that can be up and working within 10 minutes, and serves as a reference for building a production action endpoint.

故障排查工具Troubleshooting tools

  • 可操作邮件调试器:一个 Outlook 加载项,便于开发人员检查可操作邮件中的邮件卡有效负载,并确定导致邮件卡无法呈现的原因。Actionable Messages Debugger: an Outlook add-in that allows developers to inspect the card payload in their actionable messages and identify why the card is not rendering.