Outlook 2013 - Script to Create Rule to Delay All Sent Messages by X Minutes

TheBLain used Ask the Experts™
I'm able to manually create such a rule via the wizard in Outlook, but I need to deploy this rule to 50+ workstations.  Since exporting and importing rules via script seems like a dead end, what about just re-creating the rule via script?  That should be easy enough to deploy via Group Policy.  Any experts want to way in on this?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Will SzymkowskiSenior Solution Architect
Most Valuable Expert 2015
Top Expert 2015

What you could do here is create an Outlook rule using Powershell (see link below)

Once you have the script configured you can then deploy this via GPO logon script.

Thats how you can deploy this to multiple users.

Dirk MareSystems Engineer (Acting IT Manager)

I would do this at Server level are you using Exchange? I know MailMarshal can also do this.

TheBLainNetwork Administrator


Will - I didn't know PowerShell was an option for this!  That's awesome as it's standardized across the network and easy to deploy.  May take a bit to figure out exactly how to script it, but the example you posted looks quite similar to the VB code I already have.

Dirk - We are indeed running Exchange, but I was under the impression that delaying messages was not possible at that level (at least not with standard transport rules).  Is there something I'm missing?
Network Administrator
Will - Looks like rules with deferred delivery/delayed send cannot be created programmatically (per MS).

We ended up creating a VBA script that runs as a background macro in Outlook (see code below).  If "immediate" is in the subject line it sends immediately as usual, if not it delays send by 5 minutes.  This parks it in the Outbox, allowing users to make any needed corrections before it sends for good.

As for deployment, we push out a pre-configured Outlook OTM (macro) file.  Not the most elegant solutions to be sure, but it works for now.

Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  Dim objMailItem As MailItem       ' to hold mail item
  Dim intErrNumber As Integer
  On Error GoTo Err_Handler         'Error Handling
  Set objMailItem = Item            'Set object to mail item just sent
  'If objMailItem.Subject <> "Immediate" Then
  If InStr(1, objMailItem.Subject, "Immediate", vbTextCompare) = 0 Then
    objMailItem.DeferredDeliveryTime = DateAdd("n", 5, Now)     'Delay is + 2 minutes
   End If
  Exit Sub
'Due to lack of concentration of the code writing genius there has been a bit of an error,
'  lets tell someone about it by popping up a message box with a detailed description on the screen.
  intErrNumber = Err.Number
  If intErrNumber = 13 Then
    MsgBox ("An error has occurred on line " & Erl & ", with a description: " & Err.Description & ", and an error number " & _
  End If
End Sub

Open in new window

TheBLainNetwork Administrator


Sometimes pre-packaged solutions are simply unavailable, and you need to craft something from scratch.  Such was the case here.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial