COMMAIL Sample: Demonstrates an Automation Client Application with Compiler COM Support 

Download sample

COMMAIL is a standalone Automation client. It automates MAPI for Microsoft Exchange 4.0 (or later) or Microsoft Outlook. This sample sends an e-mail message which contains its source code to a specified e-mail recipient.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

Building and Running the Sample

To build this sample with Microsoft Office XP, be sure that the macro OfficeXP is defined in your code as follows: #define OFFICEXP 1.


If you are running Visual C++ Express Edition, you might need to install the Platform SDK before running this sample. For information on how to do this, see How to: Use Visual C++ Express Edition with the Microsoft Platform SDK.

To build and run this sample

  1. Open the solution commail.sln.

  2. Modify paths and file names in the source code by following the instructions given in the //To DO lines in commail.cpp.

  3. Change the recipient e-mail name and other e-mail parameters. Search the source code for #pragma for instructions on what you need to modify.

  4. Add the directory path to olemsg32.dll (Office 97) or cdo.dll (Office 2000 and Office XP). You can add this file to your Include files path in the VC++ Directories dialog box.

  5. On the Build menu, click Build.

  6. On the Debug menu, click Start Without Debugging.

Look at the type library header files (.tlh and .tli). Compare the COM interfaces in the header files with interfaces of the same type library displayed by OLEVIEW.


This sample demonstrates the following keywords:

dispinterface; #import; _com_ptr_t; _variant_t; _bstr_t; _com_error

See Also

Community Additions