我正在尝试从MFC代码中打开Outlook,该代码将发送带附件的邮件。但是我无法添加附件,因为我不知道使用什么方法,即使发送邮件,前景也没有打开,邮件也是直接发送的。
我使用了以下代码:
void COutlookDlgDlg::OnBnClickedOpenoutlook()
{
CApplication olApp;
COleException e;
if (!olApp.CreateDispatch(_T("Outlook.Application"), &e)) {
CString strErr;
strErr.Format(_T("CreateDispatch() failed w/error 0x%08lx"), e.m_sc);
AfxMessageBox(strErr, MB_SETFOREGROUND);
return;
}
CNameSpace olNs(olApp.GetNamespace(_T("MAPI")));
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
olNs.Logon(covOptional, covOptional, covOptional, covOptional);
CMailItem olMailItem(olApp.CreateItem(olMailItem));
olMailItem.put_To(_T("xyz@abc.com"));
olMailItem.put_Subject(_T("xyz..."));
olMailItem.put_Body(_T("Hi mnc,\n\n")
_T("\tMail for testing!\n\n"));
olMailItem.Send();
olNs.Logoff();
}