Forum Discussion
AndreRadtke
Feb 21, 2025Brass Contributor
Configure autoreply with rules via PowerShell
Hello,
I need a solution where I can set the autoreply agent in outlook with a rule via powershell. I am using exchange online. In the outlook client on my laptop I can activate the autoreply agent and then set additional rules like in my screenshot.
However I can´t find a way to do exactly that with powershell. The only thing I can find is that I can activate the autoreply but without rules using Set-MailboxAutoReplyConfiguration. But this CMDlet does not provide options for setting rules for the autoreply agent.
Why I need rules for autoreply?....well, I don´t want to forward maiosl marked as private, personal or companyconfidential.
Does anybody know a way to creat autoreply with such rules by powershell?
Cheers Andre
- AndreRadtkeBrass Contributor
Thank you for your reply. The problem is that transport rules and inbox rules also are not going to be deactivated if the user returns to the office, sees the message in his outlook that his autoreply is activated and deactivates it by pushing the button at the banner. Thias is what the customer need. A secretary is activating the autoresponder for the person that reports that he is ill and cannot come to work and the secretary will activate the autoresponder for the employee respecting that private, personal and company confidential mails are not forwarded but all other mails are forwarded to a person the secretary selects (most of the time the manager of the person how got ill). Back in the days the customer had exchange onpremises and a tool for this purpose, but by migrating to exo and the tool is no longer developed, they need a new solution and Ithought I could solve it with powerautomate triggeriung a runbook.
PowerShell cmdlets will not help you here, as you've already noticed. You can however configure such rules via EWS, though this might be an overkill if you are configuring this for your own mailbox. Or any mailbox you have access to via Outlook. For such, simply use Inbox rules, it's what autoresponder rules are effectively, just exposed via a different UI. If you are interested in how they work on the backend, see this article: https://learn.microsoft.com/en-us/exchange/troubleshoot/email-delivery/understand-troubleshoot-oof-replies
If you do need to do this programmatically, here's a sample article: https://www.michev.info/blog/post/5773/configure-an-auto-reply-rule-for-microsoft-365-mailboxes-via-ews
- AnkidoIron Contributor
Hi AndreRadtke,
1- First, we enable the auto-reply for the user.# Enable Auto-Reply for a user Set-MailboxAutoReplyConfiguration -Identity "email address removed for privacy reasons" ` -AutoReplyState Enabled ` -InternalMessage "I am out of the office and will return soon." ` -ExternalMessage "I am out of the office and will return soon." ` -ExternalAudience All
2- Then, we create a transport rule to block emails marked as "Private", "Personal", or "CompanyConfidential" from triggering the auto-reply.
# Create a transport rule that blocks emails with specific sensitive labels New-TransportRule -Name "Block Sensitive Emails from Auto-Reply" ` -SentTo "email address removed for privacy reasons" ` -SentFromScope NotInOrganization ` -HeaderContainsMessageHeader "Sensitivity" ` -HeaderContainsWords "Private", "Personal", "CompanyConfidential" ` -RejectMessageReasonText "We cannot send an auto-reply for sensitive emails."
Feel free to reach out