[There is now an update at http://www.metalvortex.com/blog/2011/06/30/617.html]
I recently changed Outlook 2010 from my POP3 account to an IMAP account with Google. When I first initialised Outlook 2010 it took a very long time for all the folders to by synched. But once this initial synchronisation was completed further sync actions were quite rapid so I was quite pleased with that especially with others reporting slow continuous IMAP sync times.
However, there was one problem; Outlook 2010 does not provide a notification message for arrival of new mail via IMAP. That seemed to be an easy one to fix; I set up an Outlook rule to provide a notification for arrival of new emails for the IMAP account. This was a partial success. The notification window only stays on the screen for a few seconds before disappearing, the Outlook taskbar icon does not change, and the Outlook SysTray icon also does not change (the Outlook SysTray icon is hidden on my system anyway).
What this means is that if I am away momentarily and return to the PC I have no way of determining if new mail has been received except by manually switching to the Outlook window. Not ideal. But I had a solution; AutoHotkey.
I actually already use AutoHotkey to automate some tasks on my system so I hoped to be able to generate a pop-up window when new mail arrives. This pop-up window would appear on the taskbar and also on the SysTray if I so wished. This was successful. I created an .EXE file from the following AutoHotkey script:
#NoEnv ; standard AutoHotkey header
SendMode Input ; standard AutoHotkey header
SetWorkingDir %A_ScriptDir% ; standard AutoHotkey header
MsgBox, 1, New mail notification, Switch to Outlook?
IfMsgBox OK
{
GroupAdd, newmail, New mail notification ahk_class #32770
WinClose, ahk_group newmail
IfWinExist, Inbox – ahk_class rctrl_renwnd32
{
WinActivate, Inbox – ahk_class rctrl_renwnd32
}
else
{
Run outlook
WinWait Inbox – ahk_class rctrl_renwnd32
WinActivate Inbox – ahk_class rctrl_renwnd32
}
}
else
{
GroupAdd, newmail, New mail notification ahk_class #32770
WinClose, ahk_group newmail
}
The .EXE is executed by an Outlook rule whenever new mail arrives. Works a treat.

new mail notification
Note that selecting “OK” or “Cancel” will result in the closure of all .EXE notification windows. I chose a nice envelope icon for the .EXE file. You can choose some great ones from these two sites:
Once I got that working I found another problem. Sometimes Outlook would throw up an error that the IMAP server closed the connection.

Outlook IMAP error
This error message would be just sitting there and I would not know about it unless I switched to Outlook. AutoHotkey came to my rescue again. I actually had to use two scripts. This is the main script called IMAP_ERROR.ahk:
#NoEnv ; standard AutoHotkey header
SendMode Input ; standard AutoHotkey header
SetWorkingDir %A_ScriptDir% ; standard AutoHotkey header
Loop
{
sleep 50
IfWinExist Microsoft Outlook, Your IMAP server closed the connection
{
WinClose
}
}
I’m keeping an eye out on the IMAP error messages to determine if other error messages are being generated; if they are then I will need to change the text matching for IfWinExist. Note that the sleep command is needed to stop the infinite loop from consuming all your CPU cycles.
The other change I made was to put the following code into AutoHotkey.ahk so that the above script would always be called-up and sit there waiting:
DetectHiddenWindows On
SetTitleMatchMode 2
WinClose IMAP_ERROR.ahk – AutoHotkey
run C:\Utils\scripts\IMAP_ERROR.ahk
So far everything seems to be working as required. The code list here is quite basic and I probably need to add better error-handling and undertake some code-optimisation, but at the moment the code is fine and should assist anyone else who’s having similar problems. Hopefully the next version of Outlook will have better handling of IMAP and error messages. And thank you AutoHotkey for making this so easy to solve!
System config: Windows 7 Ultimate 64-bit, Outlook 2010 (32-bit)
[There is now an update at http://www.metalvortex.com/blog/2011/06/30/617.html]
Article by Kulvinder Singh Matharu – 2011