10

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.

2 Answers 2

12

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@MAtt Dines: Could you please explain how can I access properties (like start time, end time and subject of a meeting) inside the python script. Thanks in advance.
-1

I have never done this myself for outlook but python win32extensions work for everything that supports COM http://starship.python.net/~skippy/win32/Downloads.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.