We recommend using Visual Studio 2017

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

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 intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

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

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

Show: