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

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?
TheBLainNetwork AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
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)Commented:
I would do this at Server level are you using Exchange? I know MailMarshal can also do this.

TheBLainNetwork AdministratorAuthor Commented:
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?
TheBLainNetwork AdministratorAuthor Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TheBLainNetwork AdministratorAuthor Commented:
Sometimes pre-packaged solutions are simply unavailable, and you need to craft something from scratch.  Such was the case here.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.