Sending a Message: CMC Sample

The following code example demonstrates how you can send a message, using first the cmc_send and then the cmc_send_documents function.

/* Local variables used */

CMC_attachment  Attach;
CMC_session_id  Session;
CMC_message     Message;
CMC_recipient   Recip[2];
CMC_return_code Status;
CMC_time        t_now;

/* Build recipient list with two recipients.  Add one "To" recipient. */

Recip[0].name       = "Bob Weaver";       /* Send to Bob Weaver.      */
Recip[0].name_type  = CMC_TYPE_INDIVIDUAL;/* Bob's a person.          */
Recip[0].address    = NULL;               /* Look_up Bob's address.   */
Recip[0].role       = CMC_ROLE_TO;        /* He's a "To" recipient.   */
Recip[0].recip_flags= 0;                  /* Not the last element     */
Recip[0].recip_extensions = NULL;         /* No recipient extensions  */

/* Add one "Cc" recipient. */              

Recip[1].name       = "Mary Yu";           /* Send to Mary Yu.        */
Recip[1].name_type  = CMC_TYPE_INDIVIDUAL; /* Mary's a person.        */
Recip[1].address    = NULL;                /* Look_up Mary's address. */
Recip[1].role       = CMC_ROLE_CC;         /* She's a "Cc" recipient. */
Recip[1].recip_flags= CMC_RECIP_LAST_ELEMENT;/* Last recip't element  */
Recip[1].recip_extensions = NULL;          /* No recipient extensions */

/*  Attach a file. */

Attach.attach_title = "stock.wks";         /* Original filename       */
Attach.attach_type  = NULL;                /* No specific type        */
Attach.attach_filename  = "tmp22.tmp";     /* File to attach          */
Attach.attach_flags   = CMC_ATT_LAST_ELEMENT;  /* Last attachment     */
Attach.attach_extensions = NULL;           /* No attachment extension */

/*  Put it together in the message structure. */

Message.message_reference   = NULL;     /* Ignored on cmc_send calls. */
Message.message_type        = NULL;     /* Interpersonal message type */
Message.subject             = "Stock";    /* Message subject          */
Message.time_sent           = t_now;    /* Ignored on cmc_send calls. */
Message.text_note           = "Time to buy";   /* Message note        */
Message.recipients          = Recip;      /* Message recipients       */
Message.attachments         = &Attach;    /* Message attachments      */
Message.message_flags       = 0;          /* No flags                 */
Message.message_extensions  = NULL;       /* No message extensions    */

/*  Send the message. */

Status = cmc_send(
              Session,         /* Session ID - set with logon call   */
              &Message,        /* Message structure                  */
              0,               /* No flags                           */
              0,               /* No UI will be used.                */
              NULL);           /* No extensions                      */
    /* Error handling */


/* Now do the same thing with the send documents call and UI. */

Status = cmc_send_documents(
              "to:Bob Weaver,cc:Mary Yu",      /* Message recipients  */
              "Stock",                         /* Message subject     */
              "Time to buy",                   /* Message note        */
              CMC_LOGON_UI_ALLOWED |
              CMC_SEND_UI_REQUESTED |
              CMC_ERROR_UI_ALLOWED,/* Flags (allow various UIs)  */
              "stock.wks",         /* File to attach             */
              "tmp22.tmp",         /* Filename to carry on attachment */
              ",",                 /* Multivalue delimiter       */
              0);                  /* Default UI ID              */
    /* Error handling */