This applies to Outlook 2010 and newer, including Outlook 365, 2021, 2019, 2016.
Office users who use run-a-script rules are discovering their scripts are currently disabled (as is Start Application), thanks to a security update. When the update is installed, any existing run-a-script and run application rules will be disabled.
To fix, you need to set the EnableUnsafeClientMailRules value in the registry then restart Outlook.
Outlook 2016 and newer
HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security
DWORD: EnableUnsafeClientMailRules
Value: 1
Outlook 2013
HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Security
DWORD: EnableUnsafeClientMailRules
Value: 1
Outlook 2010
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Security
DWORD: EnableUnsafeClientMailRules
Value: 1
If you don't want to edit the registry yourself, you can use this ready-to-use .reg file.
Outlook 2016/2019/2021/365 Outlook 2013
Outlook 2010
One option is to convert the run-a-script to an ItemAdd macro. Depending on the conditions in your rule, converting it to an ItemAdd macro may be as simple as adding the application startup macro, renaming the script, and adding an If statement. For information on using ItemAdd macros, see How to use an ItemAdd Macro.

Albertan says
Hello Diane, for some reason run script is not showing even if I put 1 or 2 in the value (I have Office 365) in the specified Registry path. What could be the reason?
Shylesh KR says
To add a folder in my hard disk I edited the registry then the Script editor is not saving any data and showing as empty ?
I ran the following code in the script editor
kinldy advise
Sub saveAttachments(Item As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
dateFormat = Format(Now, "yyyy-mm-dd H-mm-ss")
saveFolder = "C:\Attachments\" & Item.SenderEmailAddress & " " & dateFormat"
If Not objFSO.FolderExists(saveFolder) Then
objFSO.CreateFolder saveFolder
End If
For Each objAtt In Item.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
kRI says
I AM UNABLE TO SELECT SCRIPTS AFTER SELECTING RUN A SCRIPT
Diane Poremsky says
The box with the scripts is empty?
Did you format the script name properly? You need something in the () - example: sub scriptname (item as mailitem)
kRI says
Yes, The box with the scripts is empty. Below script is saved in text format on my desktop folder in .txt file.
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = ""
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
kRI says
Thank you! it worked
Rafeek Masani says
I need to forward the emails received in a certain mail box to one of the sendor mentioned in the To addresses field, what rule or script should I reply
Diane Poremsky says
Will there be more than one address in the To field?
This page has samples, but will need to be tweaked if forwards go to different people each time.
https://www.slipstick.com/outlook/rules/run-script-rule-change-subject-message/
Mark says
I had my pc rebuilt and have allowed unsafe rules. The rule will move a file to a folder but doesn't run the script, no error message. Macros have been allowed etc.
Diane Poremsky says
So you have the rule moving it then running a script? You should only use conditions in the rule - actions should be in the script.
Mark says
Yes, I found the reason I had copied all the rules from a text file which still had a title in it above the scripts that prevented it working. All good now thanks.
Joe says
Just sharing this. You can do very cool things with this!
Execute PowerShell Scripts from Your Smartphone | Dmitry's Blog: Cloud, PowerShell and beyond (wordpress.com)
Nikhil says
My organisation doesn't allow to set this in registry.
Is there any other workaround for this?
I want to save an attachment from a mail which I receive daily to a folder on a network drive folder.
Please help!
Diane Poremsky says
No, there is no other way if you can't run scripts. Sorry.
Nicole says
If you have access to powershell you can try :
if((Test-Path -LiteralPath "HKCU:\SOFTWARE\Microsoft\Office\16.0\Outlook\Security") -ne $true) { New-Item "HKCU:\SOFTWARE\Microsoft\Office\16.0\Outlook\Security" -force -ea SilentlyContinue };
New-ItemProperty -LiteralPath 'HKCU:\SOFTWARE\Microsoft\Office\16.0\Outlook\Security' -Name 'EnableUnsafeClientMailRules' -Value 1 -PropertyType DWord -Force -ea SilentlyContinue
Simon says
any idea why its called EnableUnsafeClientMailRules
What exactly is unsafe about it
Diane Poremsky says
It is disabled because it can do things outside of outlook (start application is disabled too). While it is hard to install an outlook macro, there was an exploit that used run application.
Detect and remediate the Outlook rules and custom forms injections attacks. - Office 365 | Microsoft Docs
Simon says
Thank you for your quick response
Milooz says
How we can do the same thing with Office 365 ?
Thanks in advance
Diane Poremsky says
Office 365 desktop software is office 16 - just use the 2-16 keys.
Tevfik says
Thank you. This is great!
Paul G Wichtendahl says
Changed the registry and it works like you said for Office 2019. Thank you! Wonder why MSFT has not added a default rule of Forward with a Template
Diane Poremsky says
They have reply with template - not sure why they didn't think about Forward.
Paul G Wichtendahl says
I spoke prematurely. run a script is now there and the script selection dialog shows up but I cannot select a script - the dialog is empty.
Diane Poremsky says
Does the macro you want to use with a rule have a name formatted like this - specifically the part in the () ?
public sub macroname(item as mailitem)
harry benham says
hello im trying to find the "HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security" path on the registry editor, problem is there is no "Security" folder, this version of outlook is newly installed today, could this be the issue? please help if you can this is the only reason i bought outlook!
Diane Poremsky says
if the folder does not exist, you need to add it.
Biniyam Ayalew says
I changed the registry value but it is not appearing for me....anything I should add?
Diane Poremsky says
You need to restart Outlook after setting the key.
Haroon says
Hi Diane
I am having problems running my scripts from rules. It was working before my machine was rebuilt. i do remember having this issue last time but i cannot remember what i did to fix it. I have added the registry entry, have recreated the rules, restarted my machine, set the trust center setting to enable all macros . I don't get an error message when i run the rules manually or when a email arrives and I am using outlook 365 64bit. I cannot think of what else to try please help. Thanks
Diane Poremsky says
No error messages if you try to run rules manually?
Dal says
Thank you for your work on this script as follows in Outlook, but when I try to create a new rule and add a script, nothing shows up in the list to select.
' Written by Michael Bauer, vboffice.net
' //www.vboffice.net/en/developers/print-attachments-automatically
' use Declare PtrSafe Function with 64-bit Outlook
'Private Declare Function ShellExecute Lib "shell32.dll" Alias _
' "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
' ByVal lpFile As String, ByVal lpParameters As String, _
' ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder
Set Ns = Application.GetNamespace("MAPI")
Set Folder = Ns.GetDefaultFolder(olFolderInbox)
Set Items = Folder.Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
PrintAttachments Item
End If
End Sub
Private Sub PrintAttachments(oMail As Outlook.MailItem)
On Error Resume Next
Dim colAtts As Outlook.Attachments
Dim oAtt As Outlook.Attachment
Dim sFile As String
Dim sDirectory As String
Dim sFileType As String
sDirectory = "C:\Attachments\"
Set colAtts = oMail.Attachments
If colAtts.Count Then
For Each oAtt In colAtts
' This code looks at the last 4 characters in a filename
sFileType = LCase$(Right$(oAtt.FileName, 4))
Select Case sFileType
' Add additional file types below
Case ".xls", ".doc", "docx"
sFile = sDirectory & oAtt.FileName
oAtt.SaveAsFile sFile
ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
End Select
Next
End If
End Sub
I added the above code to 'ThisOutlookSession'
I have restarted Outlook.
Diane Poremsky says
That is an item add macro - it run when a new message is added to the Inbox.
Private Sub Items_ItemAdd(ByVal Item As Object)
If you want to use PrintAttachments in a rule, try putting it in a new module.
sistrunk says
Thank you for all this work, and posting it so nicely and thoroughly!
I am in a secure environment, therefore I will not be able to by-pass the Run-a-Script security. I tried to run from macro using your code:
Sub SendNew(Item As Outlook.MailItem)
Dim objMsg As MailItem
Set objMsg = Application.CreateItemFromTemplate("C:\Users\RDGRLVAS\AppData\Roaming\Microsoft\Templates\fomas.oft")
objMsg.Recipients.Add Item.SenderEmailAddress
' Copy the original message subject
objMsg.Subject = "Before 1530et - Please provide input for weekly update to BC/DCs for FOMAS and associated 6.1" & Item.Subject
objMsg.Send
End Sub
------------------
I just paste it in the VvaProject.OTM-ThisOutlookSession (Code)
-----
I am not sure if I should put it somewhere else? but it doesn't run.
Diane Poremsky says
When you can't use it in a rule, you either need to use an itemadd macro or run the macro manually. You can use a 'stub' macro to process the currently selected item with the script.
It doesn't need to be in ThisOutlookSession if its not running automatically, but should work in either ThisOutlookSession or a new module.
Sub RunScript()Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)
'macro name you want to run goes here
YourMacroName objItem
End Sub
Dan S says
I copied and paste the VBA to create a task after sending an email. When I say Yes I get an error message see attached. I did the registry thing and restarted Outlook but still get it. Please help
Diane Poremsky says
Sorry I missed this earlier. :( What macro are you using? The error 'Run-time error '438': Object doesn't support this property or method' indicates you are running the macro on a item that doesnt have the field the macro is looking for.
serg says
Why in O2016 list with scripts is empty?
Diane Poremsky says
What is the script title? Where is the script stored?
The title needs to be something like sub macroname(item as mailitem) to show in the script list. It should be in a module - while they will usually work in ThisOutlookSession, on occasion, they won't show up in the list.
Eugenia says
have you saved the script in VBA window (Alt+F11) first?
abe says
i have same problem here..
Diane Poremsky says
Did you put the script in ThisOutlookSession or in a new module?
Vince Thigpen says
Thank you! This got my rule and macro running again! While macros could be a security risk, for some of us they are definitely a time and labor saving feature!
Thanks again!
Bret S. says
I found this works for Outlook 2010 as well. Recent security updates effectively killed some of my rules that ran scripts. I simply put the same value in the HKCU\Software\Microsoft\Office\14.0\Outlook\Security key.
I did discover that beyond simply exiting and restarting Outlook, it was necessary for me to restart my workstation completely before all functionality was restored.
Diane Poremsky says
So they disabled it in 2010 now too... i hoped it might escape. :(
Bret S says
Thank you for this registry edit. A recent security update rendered some of my Outlook 2010 rules disabled. Finding no other explanations, I tried inserting the "EnableUnsafeClientMailRules" value in the \Office\14.0 portion of the registry.
While I am now able to edit the rules and the Run a Script option is back in the actions portion of the rules editor, the macros will not run. They do not throw up any error messages, they just don't run. The trust center settings have not changed any, the macros have a trusted digital signature and the macro settings are set to prompt. I don't even get the prompt now. Any ideas are welcome and appreciated.
Diane Poremsky says
What does the script do? If you add msgbox "Rule is working" at the very top of the script, does it work?
Ian McCoy says
Didn't work 2016, it worked before but this time no good, any ideas please?
Diane Poremsky says
You set the new registry key to allow run a script rules? You need to restart Outlook for it to take effect.
Bob says
Thank you very much!! this was great info that solved my issue.
Daniel says
Hi,
One of our end-users has encountered an issue where they need to enable the registry key entries listed above to run this script. However we, as the IT department, don't want to enable anything that is potentially unsafe. Is there any other way to have the script run without allowing scripts to run natively for the entire application?
Thanks,
Daniel
Diane Poremsky says
No, sorry there is not. You can sign them with selfcert and only allowed signed macros to run, but that is the extent in Outlook.
Rich says
I did not find "EnableUnsafeClientMailRules" during a registry search or by navigating via the stated path.
I got as far as HKEY_CURRENT_USERSoftwareMicrosoft" but no "office" folder was available.
Windows 7 Enterprise, MS Office 2013. Any thoughts?
Diane Poremsky says
if the keys in the path don't exist, you need to add them. This one won't exist as it's new - but many others you find on this site are not present until you add them, others are not present if you use default settings.
Dhinesh says
I have enabled the below option in regedit.
HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security
DWORD: EnableUnsafeClientMailRules
Value: 1
But still i couldn't see my macro in the Rule Wizard list. My rule wizard list is empty but i have created the macro already and its manually working fine. I have to bring the macro in my Rules wizard to automate the process. Please help me if you have any ideas!
Diane Poremsky says
Is the name of the run formatted similar to this: sub macro name (item as Mailitem)? You need that in the () to use it in a rule.
Jeff says
Thank you so much!
In order to get my existing rules out of the error state I had to open them up in edit mode and cycle all the way through the rule wizard.
Chris says
This worked for rules on the "Apply rule on messages I receive" option but did not enable it on the "Apply rule on messages I send" option.
Diane Poremsky says
Run a script rules won't work on the sent folder - you need to use itemadd and watch the sent folder or use rules to move messages then watch those folders using itemadd (as long as there aren't too many folders to watch).
https://www.slipstick.com/developer/itemadd-macro/
Sam says
What should I add in the script option please?
Diane Poremsky says
If run a script is missing from the rules actions, you need to set the registry key - either add the key yourself or use the prepared reg file. Then you'll be able to call a script from a rule. Info and samples are at https://www.slipstick.com/outlook/rules/outlooks-rules-and-alerts-run-a-script/
jerry norbury says
I enabled it this way - and the the "run a script" now shows up, I can choose a sub to execute, but the VBA is still not running as far as I can tell.
I tried the most trivial of scripts with only a debug.print item.subject in it.
Diane Poremsky says
is macro searcuty set to low?
dan says
what is macro searcuty and where set it?
Diane Poremsky says
File, options, Trust center.. under macro security.
Rob Latour says
Thanks Diane! This resolved my problem right away. It really great that people such as yourself take the time and apply the effort to post solutions to solve problems of people you may never know!
Sam O\'Connor says
Thank you Diane! This update brought one of my processes to it's knees. You've given it a second chance!
marc says
I am struggling
I am trying to complete the task of:
When an email comes into the inbox of a shared mailbox, create a task
I have done all the above, this works if i run it manually but doesnt detect when a new message appears, ideally be nice to move this to a sub folder one a task is created
Diane Poremsky says
For a shared mailbox, you can't use a run a script pule - rules only work correctly if the mailbox is opened as an account, not as a shared mailbox. You need to use an itemadd macro - this watches the folder and runs when the message arrives.
https://www.slipstick.com/developer/code-samples/process-items-shared-mailbox/