Vh_ wrote:
Newly recieved emails. this would just be a continuous loop always running, checking the inbox.
if I received the email it would prompt me before executing, so I could finish my current task at work.
Below are several event triggers that can be used related to new emails in Outlook:
This is the most basic. It triggers the procedure anytime a new email is received.
Code: Select all
olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")
EventApp_NewMail()
{
MsgBox % NEW MAIL
}
It does not give you a handle to the new email though and it can be problematic to figure out what email was received if several are received in the same download.
This is better. The procedure is passed a list of IDs for all emails downloaded in the last batch.
Code: Select all
;~ NEW MAIL USING EXCHANGE LIST
global olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, "EventApp_")
EventApp_NewMailEx(IDs)
{
IDs := StrSplit(IDs, ",")
for index, ID in IDs
MsgBox % olApp.Session.GetItemFromID(ID).Subject
}
Another approach is to set an event trigger for when a new item is added to a folder.
Code: Select all
olApp := ComObjActive("Outlook.Application")
olNameSpace := olApp.GetNamespace("MAPI")
olFolderItems := olNameSpace.Folders("Account Display Name").Folders("Inbox").Folders("Important Stuff").Items
ComObjConnect(olFolderItems, "EventFolderItems_")
EventFolderItems_ItemAdd(olItem)
{
MsgBox % olItem.Subject
}
This will trigger everytime a new item is added to the Important Stuff subfolder of the Inbox for a specific account.
Connecting to an objects events is very similar to the way hotkeys work. Hotkeys are events that trigger a procedure. In all of these examples the "Event" procedure is trigger anytime the event occurs in the object connected.
FG