Is there any way to run the python script using outlook rules. I see an option of running the script but when i click, an empty box appears. How do i get the script in that box. I know it can be done through VBS but I want a python script to appear in that window.
The 'box' you mention is for selecting an Outlook VB script which you have written. If you want to run python code using this method, you are going to need to write the VBA which triggers it and then select that.
Alt+F11 from Outlook opens the VBA window, then in the white space under Project1, right click and Insert a Module. Open the module and start scripting.
To run your python code, [and I assume here you've got the Windows environmental PATH variable set for Python] use the following format for a sub routine
Sub run_python()
Shell("python C:\path\to\the\filename.py")
End Sub
The 'Shell' command above passes what is in the " " to the windows shell prompt. If it runs there, it will run here - or that's the theory! Obviously you'll need the correct drive letter in the file path.
However, to get something that appears in the script list it has to be a certian type of script/Item. You can use "Outlook.MailItem":
Sub run_python(Item As Outlook.MailItem)
Shell("python C:\path\to\the\filename.py")
End Sub
That should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With