Click here to Skip to main content
12,760,703 members (35,417 online)
Click here to Skip to main content
Add your own
alternative version


43 bookmarked
Posted 17 Apr 2001

Outlook inbox checker

, 17 Apr 2001
Rate this:
Please Sign up or sign in to vote.
Sample code on how to use tray icons and check Exchange mailbox.

Sample Image - MailCheck.gif


This article is about checking new mail arrival in your Exchange inbox. It is not intended as a "how-to", as the code is not very well designed. You can rather think of it as my contribution to this very good web site. It provides an example of code re-using, and a ready-to-use application for checking mail.

GUI speaks French. You can easily turn it into your language of choice, by editing dialog, menu and strings resources.

What does it do?

The MailCheck application connects to your Exchange server using your default profile. Then it shows a dialog:

Sample Image - MailCheck.gif

telling you whether you have new mail or not. When you close that window, it iconizes itself to the system tray. The icon in the system tray changes when new mail arrives, and it beeps. Once you have restored the dialog window, new mail is considered checked, and the icon changes again. A menu attached to the tray icon offers to run Outlook.


Part of the code comes from Microsoft foundation class library: Wakeme by Vajira Weerasekera. It concerns all the MAPI stuff to connect to your Exchange server and check your inbox.

Another part of the code comes from Daniel Zilcsak. You can read his excellent article System Tray Icons - Minimize Your Application To Tray" on this site.

Icons were copied from the excellent POP checker Magic Mail Monitor by Valeriy Ovechkin.

The ugly work

I simply followed Daniel Zilcsak's guidelines on how to use his CTrayIcon class. I created my MFC project, using a dialog-based application. The application's class is CMailCheckApp, and the dialog's class is CMailCheckDlg. I changed CMailCheckDlg to derive from CTrayDialog.

Then I glued Microsoft's sample CWakemeApp, and removed all code that concerns GUI. I added a CMailCheckDlg member variable, named dlg, to CWakemeApp, so that the dialog gets created when the Wakeme app is created. At last, theWakeme CWakemeApp application instance is created in CMailCheckApp::InitInstance instead of the CMailCheckDlg, and theWakeme.dlg.DoModal() is called. That's it ! (I told you it was ugly). Of course, I added the necessary code to handle GUI.

My only real contribution was to code the way to find the path to an Office application (Outlook). Let's have a closer look at this part, which you may find more interesting:

CString CMailCheckDlg::GetOutlookPath()
    // In case we don't find anything,
    // let's try at least default installation path
    const CString defaultPath = 
      "C:\\Program Files\\Microsoft Office\\Office\\Outlook.exe";

    HKEY hKey;
    TCHAR szCLSID[255];
    TCHAR szPath[255];
    DWORD dwBufLen = 255;
    LONG lRet;

    // Find Microsoft's CLSID for Outlook.
    // You can also use here Excel.Application, 
    // Word.Application, etc. Whatever you find in the registry.
                    &hKey) != ERROR_SUCCESS) return defaultPath;

    lRet = RegQueryValueEx(hKey,

    if(lRet != ERROR_SUCCESS) return defaultPath;

    dwBufLen = 255;
    // Now read registry for the CLSID we found.
    // Default key under LocalServer32 is
    // installation path.
    CString key = "Software\\Classes\\CLSID\\"+ 
                     CString(szCLSID) +"\\LocalServer32";
                    &hKey) != ERROR_SUCCESS) return defaultPath;

    lRet = RegQueryValueEx(hKey,

    if(lRet != ERROR_SUCCESS) return defaultPath;

    return szPath;


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Xavier Dusart
Systems Engineer
France France
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralProblem with Compile in C++.NET Pin
Sergioc3-Mar-04 2:03
memberSergioc3-Mar-04 2:03 
GeneralGetOutlookPath() revisited Pin
Dr. Versaeg13-Jan-04 7:03
memberDr. Versaeg13-Jan-04 7:03 
GeneralOutlook/Messaging server communication Pin
Cuong Tu Bang6-Nov-03 18:42
memberCuong Tu Bang6-Nov-03 18:42 
GeneralRe: Outlook/Messaging server communication Pin
ricoh ron16-Mar-11 21:05
memberricoh ron16-Mar-11 21:05 
GeneralBug Pin
Xavier Dusart21-Oct-03 22:19
memberXavier Dusart21-Oct-03 22:19 
GeneralRe: Bug Pin
Led4-Nov-03 4:52
memberLed4-Nov-03 4:52 
GeneralGreat Code man! Pin
JeffDog12-Dec-02 12:44
memberJeffDog12-Dec-02 12:44 
GeneralKey Code Pin
Anonymous8-May-04 20:38
sussAnonymous8-May-04 20:38 
GeneralUpdate Outlook Contacts Database Pin
Chitra CK1-Jun-02 0:37
memberChitra CK1-Jun-02 0:37 
GeneralMAPI Pin
kolmol28-Mar-02 1:04
memberkolmol28-Mar-02 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 18 Apr 2001
Article Copyright 2001 by Xavier Dusart
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid