Question

I have a working method which will successfully open Outlook (and other mail clients), open a new message window, and set the body and subject fields with provided strings, and attach one or more files indicated by a vector of our internal filepath object. I'm trying to extend this to add a recipient in the To: field. The code below omits all of the subject/body/path stuff for brevity and just shows what I've done with recipients.

void createMailMessage( const char *recipientAddr, const char *subject, const char *body, const std::vector<FSPath> &attachments) {
  // first get all of the const char* into std::wstring 
  // ommitted here for brevity

  MapiMessageW message = { 0 };
  MapiRecipDescW *recipients = NULL;
  if (recipientAddr != NULL) {
    recipients = new MapiRecipDescW[1];
    memset(recipients, 0x00, sizeof(MapiRecipDescW) ) // only one recipient
    recipients[0].lpszAddress = (PWSTR) recipStrW.c_str(); // recipStrW is from omitted code above
    recipients[0].ulRecipClass = MAPI_TO;
    message.nRecipCount = (ULONG) 1;
    message.lpRecips = recipients;
  }

  // fill in the rest of the message info here
  // this stuff is already working and i left it unchanged

  MAPISendMailHelper(NULL, NULL, &message, MAPI_LOGON_UI|MAPI_DIALOG, 0);
}

In the debugger I can see that the message struct is still well-formed, simply with the addition of a pointer to the recipients struct and the nRecipCount field filled correctly. That struct is also well-formed, with the expected address string and class value. When the code executes, it reaches the same call that produces the new message dialog ( pfnMapiSendMailA() in MapiUnicodeHelp.h ), but does not seem to execute it.

Help! What am I missing?!

Thanks in advance!

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top