如何通过Logic Apps连接Exchange Online实现多邮箱自动回复?是否需REST API/EWS?
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
MailboxSettingsendpoint) 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):
- Go to the Azure AD portal, register a new App Registration.
- 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).
- Add Application Permissions (not delegated—these let your app access all mailboxes without user login) >
- For EWS (if you go this route):
- Add the
Exchange.ManageAsAppapplication 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"}
- Add the
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
- Get an Access Token:
- Create a POST request to
https://login.microsoftonline.com/your-tenant-id/oauth2/v2.0/token - Use
x-www-form-urlencodedbody with these parameters:grant_type:client_credentialsclient_id: Your app’s client IDclient_secret: Your app’s client secretscope:https://graph.microsoft.com/.default
- Send the request—you’ll get an
access_tokenin the response.
- Create a POST request to
- 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.
- Make a GET request to
- Set Auto-Reply:
- Make a PATCH request to the same URL as above.
- Add headers:
Authorization: Bearer your-access-tokenandContent-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)
- Get an access token similar to Graph, but use
scope: https://outlook.office365.com/.default - Make a POST request to
https://outlook.office365.com/EWS/Exchange.asmx - Add headers:
Authorization: Bearer your-access-tokenandContent-Type: text/xml - 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:
- In the Azure Portal, go to Logic Apps > Custom Connectors > New Custom Connector > Import from Postman collection.
- Export your Postman collection (save as JSON) and upload it here.
- Walk through the connector setup:
- Verify basic info (name, description).
- Check each operation’s parameters, headers, and body schemas—make sure the
Authorizationheader 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.
- 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 /usersand 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
$selectand$filterparameters 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

