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

如何通过Logic Apps连接Exchange Online实现多邮箱自动回复?是否需REST API/EWS?

Scaling Auto-Reply to Exchange Online in Logic Apps: A Step-by-Step Guide

Hey Felix, great question—let’s walk through this step by step since you’re new to Logic Apps and looking to scale that auto-reply solution from a single Outlook mailbox to your entire Exchange Online environment. You’re on the right track with REST APIs and custom connectors, so let’s break this down into actionable steps.

First: Pick the Right API (Graph > EWS)

Microsoft’s current recommendation is Microsoft Graph API over Exchange Web Services (EWS) for Exchange Online integrations. Here’s why:

  • Graph is actively maintained with new features, while EWS is in maintenance mode (no new features added).
  • Graph has more granular permission controls, perfect for multi-mailbox/company-wide scenarios.
  • It supports all auto-reply functionality (via the MailboxSettings endpoint) and integrates seamlessly with Azure AD for authentication.

That said, if you have a specific need to use EWS, we’ll cover that too—but start with Graph if you can.

Second: Set Up Permissions (Using Your EAC Access)

Since you have Exchange Admin Center access, you’ll need to register an Azure AD application to get API access (this is required for both Graph and EWS):

  1. Go to the Azure AD portal, register a new App Registration.
  2. For Graph API:
    • Add Application Permissions (not delegated—these let your app access all mailboxes without user login) > MailboxSettings.ReadWrite (to view and modify auto-replies).
    • Click Grant Admin Consent (you’ll need global admin rights for this, which your EAC access should cover).
  3. For EWS (if you go this route):
    • Add the Exchange.ManageAsApp application permission and grant admin consent.
    • In EAC, go to Settings > Mail Flow > Transport Rules (or use Exchange Online PowerShell) to add your app’s ID to the EWS allowlist with:
      Set-OrganizationConfig -EwsApplicationAccessPolicy EnforceAllowList
      Set-OrganizationConfig -EwsAllowList @{Add="your-app-client-id"}
      

Third: Test API Calls with Postman

Before building the connector, verify your API works in Postman—this saves headaches later.

Testing Graph API Auto-Reply

  1. Get an Access Token:
    • Create a POST request to https://login.microsoftonline.com/your-tenant-id/oauth2/v2.0/token
    • Use x-www-form-urlencoded body with these parameters:
      • grant_type: client_credentials
      • client_id: Your app’s client ID
      • client_secret: Your app’s client secret
      • scope: https://graph.microsoft.com/.default
    • Send the request—you’ll get an access_token in the response.
  2. Fetch Current Auto-Reply Settings:
    • Make a GET request to https://graph.microsoft.com/v1.0/users/user-email@company.com/mailboxSettings/automaticRepliesSetting
    • Add a header: Authorization: Bearer your-access-token
    • You’ll see the user’s current out-of-office config.
  3. Set Auto-Reply:
    • Make a PATCH request to the same URL as above.
    • Add headers: Authorization: Bearer your-access-token and Content-Type: application/json
    • Use this sample body (adjust dates/messages as needed):
      {
        "status": "Scheduled",
        "scheduledStartDateTime": {
          "dateTime": "2024-05-01T00:00:00",
          "timeZone": "UTC"
        },
        "scheduledEndDateTime": {
          "dateTime": "2024-05-07T00:00:00",
          "timeZone": "UTC"
        },
        "externalReplyMessage": "I'm out of office until May 7th. Please contact Jane Doe for urgent requests.",
        "internalReplyMessage": "I'm out of office until May 7th. Reach out to Jane if you need immediate help."
      }
      

Testing EWS (If Needed)

  1. Get an access token similar to Graph, but use scope: https://outlook.office365.com/.default
  2. Make a POST request to https://outlook.office365.com/EWS/Exchange.asmx
  3. Add headers: Authorization: Bearer your-access-token and Content-Type: text/xml
  4. Use this SOAP body to fetch auto-reply settings:
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
                   xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
                   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Header>
        <t:RequestServerVersion Version="Exchange2016" />
      </soap:Header>
      <soap:Body>
        <m:GetUserOofSettingsRequest>
          <m:Mailbox>
            <t:EmailAddress>user-email@company.com</t:EmailAddress>
          </m:Mailbox>
        </m:GetUserOofSettingsRequest>
      </soap:Body>
    </soap:Envelope>
    

Fourth: Build a Custom Connector in Logic Apps

Once your Postman tests work, turn those requests into a reusable Logic Apps connector:

  1. In the Azure Portal, go to Logic Apps > Custom Connectors > New Custom Connector > Import from Postman collection.
  2. Export your Postman collection (save as JSON) and upload it here.
  3. Walk through the connector setup:
    • Verify basic info (name, description).
    • Check each operation’s parameters, headers, and body schemas—make sure the Authorization header is set to use OAuth 2.0.
    • Configure the OAuth 2.0 settings with your app’s client ID, client secret, tenant ID, and token endpoint.
  4. Save the connector—it’s now ready to use in any Logic Apps workflow.

Fifth: Build Your Auto-Reply Workflow

Now put it all together in Logic Apps. Here’s a sample workflow for company-wide auto-replies:

  • Trigger: Use a Recurrence trigger (e.g., daily at 9 AM) to check for users with upcoming out-of-office dates.
  • Action 1: Call Graph API (via your custom connector) to GET /users and fetch all company users.
  • Action 2: Add a For Each loop to iterate over each user.
  • Action 3: Inside the loop, call your custom connector to fetch the user’s current auto-reply settings.
  • Action 4: Add a Condition to check if the user needs an auto-reply (e.g., based on their calendar events or a shared list).
  • Action 5: If the condition is met, call your custom connector to set the auto-reply.
  • Action 6: Optional—add a notification (e.g., Teams message to your admin team) confirming the auto-reply was set.

Pro Tips for Scaling

  • Batch Processing: For large companies, use Graph’s $select and $filter parameters to limit users fetched (e.g., only users with upcoming calendar events).
  • Error Handling: Add Scope actions with error handling to catch failed API calls and retry or log them.
  • Test First: Validate the workflow with a small group of test users before rolling out to the entire company.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 18:23:10