我有一个工作方法,它将成功打开Outlook(和其他邮件客户端),打开一个新的消息窗口,并使用提供的字符串设置正文和主题字段,并附加一个或多个由我们内部的向量指示的文件filepath对象。我正在尝试扩展它以在To:字段中添加收件人。为简洁起见,下面的代码省略了所有主题/正文/路径内容,只显示了我对收件人所做的事情。
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);
}
在调试器中,我可以看到消息结构仍然格式正确,只需添加指向收件人结构的指针并正确填充nRecipCount字段即可。该结构也是格式良好的,具有预期的地址字符串和类值。当代码执行时,它会到达产生新消息对话框的相同调用(MapiUnicodeHelp.h中的pfnMapiSendMailA()),但似乎不执行它。
帮助!我错过了什么?!
提前致谢!