Platform SDK: MAPI

Sending a Message Simply: Simple MAPI Sample

This example shows the simplest way you can send a message. An essentially blank message is created and passed to the MAPISendMail function with parameters that cause Simple MAPI to use dialog boxes to create the content of the message. First, the client defines the variables it needs. Note that your client will not hard-code the attachment path name or filename in the MapiFileDesc structure.

// Example 1:
// Send a mail message containing a file and prompt for 
// recipients, subject, and note text.

ULONG err;
MapiFileDesc attachment = {0,         // ulReserved, must be 0
                           0,         // no flags; this is a data file
                           (ULONG)-1, // position not specified
                           "c:\\tmp\\tmp.wk3",  // pathname
                           "budget17.wk3",      // original filename
                           NULL};               // MapiFileTagExt unused
// Create a blank message. Most members are set to NULL or 0 because
// MAPISendMail will let the user set them.
MapiMessage note = {0,            // reserved, must be 0
                    NULL,         // no subject
                    NULL,         // no note text
                    NULL,         // NULL = interpersonal message
                    NULL,         // no date; MAPISendMail ignores it
                    NULL,         // no conversation ID
                    0L,           // no flags, MAPISendMail ignores it
                    NULL,         // no originator, this is ignored too
                    0,            // zero recipients
                    NULL,         // NULL recipient array
                    1,            // one attachment
                    &attachment}; // the attachment structure
 

Next, the client calls the MAPISendMail function and stores the return status so it can detect whether the call succeeded. You should use a more sophisticated error reporting mechanism than the C library function printf.

err = MAPISendMail (0L,          // use implicit session.
                    0L,          // ulUIParam; 0 is always valid
                    &note,       // the message being sent
                    MAPI_DIALOG, // allow the user to edit the message
                    0L);         // reserved; must be 0
if (err != SUCCESS_SUCCESS )
    printf("Unable to send the message\n");