You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Microsoft API发送可操作消息(无需集成Connectors)

回答:无需集成Connectors,通过Microsoft API发送可操作邮件的方案

Great question! You absolutely can send actionable emails (with Approve/Reject buttons) using Microsoft APIs without integrating Connectors—here's how to make it work for your bulk email workflow and sync actions back to your app:

Core Approach: Microsoft Graph API + Adaptive Card Inline Actions

The key here is using Outlook Actionable Messages powered by Adaptive Cards, specifically leveraging Inline Actions (not Connector Actions). Inline Actions let buttons in the email directly call your custom backend API, so you don't need to rely on Microsoft Connectors at all.

Step-by-Step Implementation

1. Design Your Adaptive Card with Inline Actions

Create an Adaptive Card JSON that includes your Approve/Reject buttons, configured to send HTTP POST requests to your backend. Each button will pass necessary context (like request ID, user identifier) so your app can map the action to the correct request.

Example Adaptive Card snippet:

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.4",
  "body": [
    {
      "type": "TextBlock",
      "text": "Please approve or reject this request:",
      "size": "Large"
    },
    {
      "type": "TextBlock",
      "text": "Request ID: REQ-12345",
      "margin": "Medium"
    }
  ],
  "actions": [
    {
      "type": "Action.Http",
      "title": "Approve",
      "method": "POST",
      "url": "https://your-app-domain.com/api/requests/approve",
      "body": "{\"requestId\": \"REQ-12345\", \"userId\": \"user@example.com\"}"
    },
    {
      "type": "Action.Http",
      "title": "Reject",
      "method": "POST",
      "url": "https://your-app-domain.com/api/requests/reject",
      "body": "{\"requestId\": \"REQ-12345\", \"userId\": \"user@example.com\"}"
    }
  ]
}

2. Send Bulk Emails via Microsoft Graph API

Use the Graph API's sendMail endpoint (or batch requests for bulk sending) to deliver emails with the Adaptive Card embedded. You'll need to include the Adaptive Card as a MIME part in the email, with the content type application/adaptivecard+json.

Pro tip: Use batch requests (POST /$batch) to handle large volumes of emails efficiently—this reduces the number of API calls and improves performance.

For authentication, use application permissions (like Mail.Send) if your app is sending emails without user interaction (ideal for bulk workflows).

3. Handle Callback Requests & Sync to Your App

When a user clicks a button, Outlook will send a POST request to your backend API. You need to:

  • Validate the request signature: Microsoft signs these requests to ensure they're legitimate. You'll need to verify the signature using the public keys provided by Microsoft to prevent spoofing.
  • Process the action: Update the request status in your app (e.g., mark as Approved/Rejected) using the context passed in the request body.
  • Send a response: Return a 200 OK status to Outlook, and optionally include an Adaptive Card update to show the user the action was successful (e.g., "Request Approved!").

Critical Notes to Avoid Issues

  • Domain Verification: To prevent Outlook from blocking your actionable buttons, you must verify ownership of your backend domain by adding a TXT record to your DNS. This tells Microsoft your API is trusted.
  • Bulk Limits: Be aware of Graph API throttling limits for bulk operations. Implement retry logic and batch sizing to stay within these limits.
  • Fallback Content: Always include a plain text or HTML fallback in your email for clients that don't support Adaptive Cards (e.g., older email clients). This ensures all users can see the request details, even if they can't use the buttons.

Example Graph API Send Mail Request

Here's a simplified example of sending an email with an Adaptive Card via Graph API:

POST https://graph.microsoft.com/v1.0/users/{sender-email}/sendMail
Content-Type: application/json

{
  "message": {
    "subject": "Request Approval Required",
    "body": {
      "contentType": "HTML",
      "content": "<p>Please review the request below. <br> If you're using Outlook, you can approve/reject directly from this email.</p>"
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "user@example.com"
        }
      }
    ],
    "attachments": [
      {
        "@odata.type": "#microsoft.graph.fileAttachment",
        "name": "actionable-message.json",
        "contentType": "application/adaptivecard+json",
        "content": "{base64-encoded-adaptive-card-json}"
      }
    ]
  },
  "saveToSentItems": false
}

内容的提问来源于stack exchange,提问作者Mahadev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 18:43:14