Solved

Deploy rule for Outlook 2010

Posted on 2014-01-22
17
2,300 Views
Last Modified: 2016-02-11
We have 50+ users who use a particular application that sends emails on their behalf over SMTP. The application can be configured to bcc any emails sent to the sender.

I want to create rule that will move any emails sent from themselves to themselves (bcc) to be moved to their sent items.
However I do not want to go to every computer one by one to set this up.

Is there a way I can deploy a rule to all computer via Group Policy or in Exchange?

We're using Windows 7 Pro, Outlook 2010 and Exchange 2010 on Server 2008 R2 server.
0
Comment
Question by:antonioking
17 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 39801174
Hi, antonioking.

I'm not a group policy expert.  That said, I'm not aware of any way to deploy a rule through group policy.  However, you can create a rule via a script, so if your office uses a logon script or if a script can be pushed via a group policy, then you could do this.  If that's possible, then I can help with the script.  I'm afraid I can't help with the group policy aspect.
0
 

Author Comment

by:antonioking
ID: 39802377
Hi BlueDevilFan
A script sounds good. We do use logon scripts where group policy can't fulfill our needs.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 39802684
antonioking,

Here is the script.  It creates a rule that moves all message sent from the user's email address to the Sent Items folder except if the user's email address is in the To or CC line.  That's the only way I know of to catch BCCs since there is no rule action for BCC'd messages.  I tested the script on my computer (Win7/Office 2013) and it worked perfectly.  It should work on Office 2010 just as well.  Note that the script must run under the user's credentials to work properly.

Please give it a try and let me know if that's what you needed.

'On the next line, edit the name of the rule as desired
Const RULE_NAME = "Move BCC msgs to myself to Sent Items"
Const olRuleReceive = 0
Const olFolderSentMail = 5
Dim olkApp, olkSes, olkCol, olkRul, olkCD1, olkCD2, olkMRA
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
olkSes.Logon olkApp.DefaultProfileName
Set olkCol = olkSes.DefaultStore.GetRules()
Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)
Set olkCD1 = olkRul.Conditions.From
With olkCD1
    .Enabled = True
    .Recipients.Add olkSes.CurrentUser.Address
    .Recipients.ResolveAll
End With
Set olkCD2 = olkRul.Exceptions.ToOrCc
With olkCD2
    .Enabled = True
End With
Set olkMRA = olkRul.Actions.MoveToFolder
With olkMRA
    .Enabled = True
    Set .Folder = olkSes.GetDefaultFolder(olFolderSentMail)
End With
olkCol.Save False
olkSes.Logoff
olkApp.Quit
Set olkMRA = Nothing
Set olkCD2 = Nothing
Set olkCD1 = Nothing
Set olkRul = Nothing
Set olkCol = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
WScript.Quit

Open in new window

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Closing Comment

by:antonioking
ID: 39802703
Perfect.
Thanks!
0
 

Author Comment

by:antonioking
ID: 39802709
How can I stop the script from running once the rule has been created?
The rule duplicates itself everytime I logon.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39802742
I'll add code to check and see if the rule already exists and create it if it doesn't.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39802753
Here you go.  This version tests to see if the rule exists and only creates it if it doesn't.

Const RULE_NAME = "Move BCC msgs to myself to Sent Items"
Const olRuleReceive = 0
Const olFolderSentMail = 5
Dim olkApp, olkSes, olkCol, olkRul, olkCD1, olkCD2, olkMRA
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
olkSes.Logon olkApp.DefaultProfileName
Set olkCol = olkSes.DefaultStore.GetRules()
Set olkRul = olkCol.Item(RULE_NAME)
If Typename(olkRul) = "Nothing" Then
    Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)
    Set olkCD1 = olkRul.Conditions.From
    With olkCD1
        .Enabled = True
        .Recipients.Add olkSes.CurrentUser.Address
        .Recipients.ResolveAll
    End With
    Set olkCD2 = olkRul.Exceptions.ToOrCc
    With olkCD2
        .Enabled = True
    End With
    Set olkMRA = olkRul.Actions.MoveToFolder
    With olkMRA
        .Enabled = True
        Set .Folder = olkSes.GetDefaultFolder(olFolderSentMail)
    End With
    olkCol.Save False
End If
olkSes.Logoff
olkApp.Quit
Set olkMRA = Nothing
Set olkCD2 = Nothing
Set olkCD1 = Nothing
Set olkRul = Nothing
Set olkCol = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
WScript.Quit

Open in new window

0
 

Author Comment

by:antonioking
ID: 39802765
Thanks!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39802774
You're welcome!
0
 

Author Comment

by:antonioking
ID: 39806124
Hi BlueDevilFan
Wonder if you could help one an error..

Some users are getting the error

Line: 9
Char 1:
Error: The attempted operation failed. An object could not be found.

Why is this?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39806140
Add this command

On Error Resume Next

after line 4.
0
 

Author Comment

by:antonioking
ID: 39806158
Thanks! That's stopped the error, but the rule doesn't get created.
To reward you for your time, I have created a new question here...

Q_28347242
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39806489
Thanks, but there's no need for another question.  I shouldn't get extra points for a problem of my own making.

The problem is the test on line 10.  I sometimes forget the differences between VBA and VBScript.  In VBA Typename would return "Nothing" while in VBScript it returns "Empty".  Change "Nothing" to "Empty" on line 10 and you're in business.  Here's the corrected version for any future readers of this question.

Const RULE_NAME = "Move BCC msgs to myself to Sent Items"
Const olRuleReceive = 0
Const olFolderSentMail = 5
Dim olkApp, olkSes, olkCol, olkRul, olkCD1, olkCD2, olkMRA
On Error Resume Next
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
olkSes.Logon olkApp.DefaultProfileName
Set olkCol = olkSes.DefaultStore.GetRules()
Set olkRul = olkCol.Item(RULE_NAME)
Debug.Write TypeName(olkRul)
If Typename(olkRul) = "Empty" Then
    Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)
    Set olkCD1 = olkRul.Conditions.From
    With olkCD1
        .Enabled = True
        .Recipients.Add olkSes.CurrentUser.Address
        .Recipients.ResolveAll
    End With
    Set olkCD2 = olkRul.Exceptions.ToOrCc
    With olkCD2
        .Enabled = True
    End With
    Set olkMRA = olkRul.Actions.MoveToFolder
    With olkMRA
        .Enabled = True
        Set .Folder = olkSes.GetDefaultFolder(olFolderSentMail)
    End With
    olkCol.Save False
End If
olkSes.Logoff
olkApp.Quit
Set olkMRA = Nothing
Set olkCD2 = Nothing
Set olkCD1 = Nothing
Set olkRul = Nothing
Set olkCol = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
WScript.Quit                                       

Open in new window

0
 

Author Comment

by:antonioking
ID: 39806510
Thanks BlueDevilFan!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39806634
You're welcome.  Sorry for the problem.
0
 

Expert Comment

by:glenn_r
ID: 40689558
I've got a similar question re how to write a vb rule (rwz) for outlook that executes an external file. I've got this working as an rwz but need to deploy to 500 client machines. Was hoping to write a script to do this. I'm a dev but new to outlook/vba/scripting and need some directions. Can you give me some advice?
see
http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_28644021.html?anchor=a40688749
0
 
LVL 54

Expert Comment

by:McKnife
ID: 40805941
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question