Save Sent messages in Shared Mailbox instead of the sender's mailbox in Exchange Online with PowerShell
I received a request from a client that was struggling with using Shared Mailboxes in Exchange Online. They wanted to be able to see all sent email messages in the Shared Mailbox “Sent” folder instead of the user's email address.
For example:
- A user has “Send As” permissions on a Shared Mailbox named “Finance@example.com”.
- The user composes a new email in Outlook and changes the “From” setting to “Finance@” and clicks the Send button.
- The email is delivered to recipients from “Finance@”.
- A copy of the sent email is stored in the user's “Sent” folder.
The issue with this process is that there is no record inside the Shared Mailbox that an email was sent from the account. Only the original sender has a copy of the message, but other users who have access to the Shared Mailbox cannot see which email messages have been sent out or which items in the inbox have been replied to.
To fix this issue, I wrote a quick PowerShell script to update all Shared Mailboxes with 2 attributes.
After running this script, a step is added to the email process:
5.
A copy of the sent email is also stored in the Shared Mailbox's “Sent” folder.
To run this script, you will need the “Exchange Administrator” role assigned to your account and the ExchangeOnlineManagement
PowerShell module installed on your computer.
Here is the script:
## Update-SharedMailboxSentFolder.ps1
## Imports a list of Shared Mailboxes (lookup or csv file), then updates the mailbox to save sent messages through "Send As" and "Send on Behalf of" in the Shared Mailbox Sent folder in addition to the sender's Sent folder.
## Requires at least the Exchange Administrator role.
## tdannecy@gmail.com 2024
Connect-ExchangeOnline
## CSV format:
## UserPrincipalName
## mailbox1@example.com
## mailbox1@example.com
#$mailboxes = import-csv -path '.\mailboxes.csv'
$mailboxes = Get-EXOMailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited
foreach ($mailbox in $mailboxes) {
$curmailbox = Get-mailbox -identity $mailbox.userprincipalname
if ($curmailbox.MessageCopyForSentAsEnabled -eq $False -or $curmailbox.MessageCopyForSentOnBehalfEnabled -eq $False) {
try {
Write-Host "Updating $($mailbox.UserPrincipalName)..."
Set-mailbox -Identity $mailbox.UserPrincipalName -MessageCopyForSentAsEnabled $true -MessageCopyForSendOnBehalfEnabled $true
}
catch {
Write-Error "Could not update $($mailbox.UserPrincipalName)"
}
}
else {
Write-Host "Skipping $($mailbox.UserPrincipalName), attribute already set"
}
}
I also saved this script as a public Gist: