Outlook desktop alert

Microsoft Outlook is not just an email client application. This outstanding software can do lot more than checking my inbox. Outlook calendar is a must today in order to keep track of my appointments and meetings. Quick notes are easily saved in Outlook as well and all my contacts are stored and synchronized with my smartphone. Outlook comes with powerful programming capabilities. Visual Basic for Applications or just VBA enables endless possibilities to extend the features. While the application is running, it usually polls external mailboxes out on the net and eventually notifies of new mail. The Outlook.SyncObject is fired periodically and it starts multiple processes to keep user’s mailboxes, calendar and other information up-to-date.

I like to check the state of my net connection every now and then. If the connection gets broken, I’d like to have an alert to quickly repair the connection. I could have installed some standalone application to do this task, but I like to keep the number of installed software as low as possible. My Outlook is running in the background and I wondered whether I could use it to make periodical checks and notify me of any exceptions raised. I wrote a simple script and hooked the SyncObject to run it once in every hour. I got my script ready and it ran smoothly checking the connection every hour. The only problem was displaying the alert if something was wrong.

The script adds a new mailbox item each time the connection gets broken. The new item is unread by default drawing my attention if I happen to check the folder. The easy way to display an alert or so called desktop alert is to create a rule, which pops up an alert window when the rule meets the requirements I have set. Now, I only needed to run the rule right after adding a new item in the folder to invoke the alert. My script first hooks the SyncObject so that it runs my script when the synchronization starts.

Dim WithEvents mySync As Outlook.SyncObject

The next step is to start my synchronization object when Outlook starts up. Outlook supports multiple SyncObjects and each of them can have different settings, for example different time intervals to fire the synchronization. I only have one SyncObject defined, so I can rely on the index number 1 when querying the object from the collection.

Private Sub Application_Startup() Set mySync = Application.Session.SyncObjects.Item(1) mySync.Start End Sub

Finally the SyncStart event is fired right after the synchronization has started. This function finds my special rule "myRule", which I want to run after checking the state of the connection.

Private Sub mySync_SyncStart() Dim ns As Outlook.NameSpace Dim myRule As Outlook.Rule Set ns = Application.GetNamespace("MAPI") Set myRule = ns.DefaultStore.GetRules.Item("myRule") Set myLogs = ns.Folders.Item("Outlook").Folders.Item("Logs") Set myItem = Application.CreateItem(olPostItem) If (connectionStatus = False) Then   With myItem     .Subject = "Problems with connection"     .Importance = olImportanceHigh     .UnRead = True     .Move myLogs   End With   myRule.Execute False, myLogs, False, olRuleExecuteUnreadMessages End If End Sub

If the connection is broken, then the script creates a new posting item and adds it into the Logs folder. The final step is to run the rule in Logs folder to find any unread items and if found, the rule then displays the desktop alert letting me know about problems with the connection.

Final words

Microsoft Oulook is an outstanding application with enormous features and functions. One can implement virtually anything with Outlook and using the powerful programming language these capabilities can be extended with no limits. Using the Outlook’s synchronization objects you can create a service, which is run periodically while the application is running. I use Outlook to check every hour some items on the Internet and found the application an excellent companion to complete this task.

Julkaistu keskiviikkona 25.1.2012 klo 20:05 avainsanoilla askartelu, harrastukset, ohjelmistot ja ohjelmointi.

Edellinen
Väskynä
Seuraava
Vaalijono