I need to create some sort of trigger in an outlook where a python script will be executed as new emails are received in inbox. I did refer to this link: How do I trigger a macro to run after a new mail is received in Outlook? and have written the following script:
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
default local Inbox
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub test_macro(ByVal item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
Ret_Val = Shell("python <path-of-python-script>")
Debug.Print "Value: ", Ret_Val
If Ret_Val <> 0 Then
MsgBox "Couldn't run python script", vbOKOnly
End If
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Although its not giving any error but due to some reasons my python script is not executing. I've configured macro settings in outlook accordingly and also created a new rule according to documentation available. But still not able to achieve the intended result.
Any help is appreciated.