I have the following which calls a Python script after receiving any email:
Option Explicit
'This "event" runs whenever there is a new email
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
'Declare as generic Object since we don't know what type of NewMail Item we got yet
Dim entry As Object
'Me refers to ThisOutlookSession, the GetNamespace is just something we always have to do in outlook
'GetItemFromID gets the mail object which we need to have to check if its an email
'or if we want to do something with it like move it to another folder
Set entry = Me.GetNamespace("MAPI").GetItemFromID(EntryIDCollection)
'Exit our event handler if this isn't an email - meetings and notifications also may pop up here
If Not TypeOf entry Is MailItem Then Exit Sub
'Call the sub that will handle the new email
passing in the email VBA object in case that is important
OnNewEmail entry
End Sub
'This Sub will be called whenever the Application_NewMailEx event is triggered with a MailItem
Private Sub OnNewEmail(ByVal email As MailItem)
Shell "C:\Program Files\Python310\python.exe C:\Users\lradico\Desktop\WWP\waites_slack.py"
End Sub
I want it to only trigger if the new email has a few specific words in the subject. The subject will be different every time, but a few words in it will remain the same.