Move spam in the Microsoft Exchange inbox faster

This article describes how you can move mails marked as spam more quickly

The G DATA Exchange Mail Security adds the header X-G-Data-MailSecurity-for-Exchange-MoveToJunkFolder: true to each spam message. These messages are automatically moved to the mailbox owner’s default junk mail folder.

This process can be performed more quickly if a server-side inbox rule is created. The rule ensures that the Exchange Server immediately moves messages to the spam folder.

The prerequisite for this is that spam filtering measures have been configured.

Exchange Shell Script

Using Exchange Management Shell, the following PowerShell script must be run to set up the rule for all mailboxes. In the first command, <Account> must be replaced with the account of the user, who is running the script:

$mailboxes = get-mailbox -resultsize unlimited | add-mailboxpermission -user <Account> -accessrights fullaccess
$mailboxes | foreach { new-inboxrule -name "MoveToJunkFolder" -mailbox $($_.Alias) -MoveToFolder "$($_.Alias):\Junk-E-Mail" -HeaderContainsWords "X-G-Data-MailSecurity-for-Exchange-MoveToJunkFolder: True" -StopProcessingRules $true -confirm:$false -force }