For the life of me, I could not find out why it was failing. Then I found out that if you pass the CC a blank string, it will fail.
As for someone's question about it failing if Outlook is not running, just add this code before you do the send:
// first, determine if Outlook is running
outlook = FindWindowEx(NULL, NULL, "rctrl_renwnd32", NULL);
if (outlook == NULL)
// need to launch outlook
ShellExecute(NULL, "open", "outlook", "", "", SW_SHOWNORMAL );
// wait for a second
Since I upgraded to SR1, when you try and send using IMAP the user is presented with a dialog box:
"A program is trying to send email on your behalf. Do you want to allow this? If this is unexpected, it may be a virus and you should choose 'No'."
At which point the user is supposed to hit Yes. A hack would be to intercept the dialog and hit Yes myself, but this is rather unprofessional.
I hope there's a switch somewhere in Outlooks options to address this. Anyone found it?
replace this line
int nError = m_lpfnSendMail(0, (ULONG) pParentWnd->GetSafeHwnd(), &m_message, MAPI_LOGON_UI | flags, 0);
int nError = m_lpfnSendMail(0, 0, &m_message, flags, 0);