R
Rui Oliveira
Add a attach file to an email in C++
I am using the following code to create a new email message in C++.
How can I add an attach file?
-----------------------
_Application olApp;
COleException e;
if(!olApp.CreateDispatch("Outlook.Application", &e)) {
CString str;
str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc);
AfxMessageBox(str, MB_SETFOREGROUND);
return;
}
// Logon. Doesn't hurt if you are already running and logged on...
_NameSpace olNs(olApp.GetNamespace("MAPI"));
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
olNs.Logon(covOptional, covOptional, covOptional, covOptional);
// Prepare a new mail message
_MailItem olMail(olApp.CreateItem(0));
olMail.SetTo("(e-mail address removed)");
olMail.SetSubject("About our meeting...");
olMail.SetBody(
"Hi James,\n\n"
"\tI'll see you in two minutes for our meeting!\n\n"
"Btw: I've added you to my contact list!");
// Send the message!
olMail.Display(COleVariant((short)TRUE));
AfxMessageBox("All done.", MB_SETFOREGROUND);
olNs.Logoff();
I am using the following code to create a new email message in C++.
How can I add an attach file?
-----------------------
_Application olApp;
COleException e;
if(!olApp.CreateDispatch("Outlook.Application", &e)) {
CString str;
str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc);
AfxMessageBox(str, MB_SETFOREGROUND);
return;
}
// Logon. Doesn't hurt if you are already running and logged on...
_NameSpace olNs(olApp.GetNamespace("MAPI"));
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
olNs.Logon(covOptional, covOptional, covOptional, covOptional);
// Prepare a new mail message
_MailItem olMail(olApp.CreateItem(0));
olMail.SetTo("(e-mail address removed)");
olMail.SetSubject("About our meeting...");
olMail.SetBody(
"Hi James,\n\n"
"\tI'll see you in two minutes for our meeting!\n\n"
"Btw: I've added you to my contact list!");
// Send the message!
olMail.Display(COleVariant((short)TRUE));
AfxMessageBox("All done.", MB_SETFOREGROUND);
olNs.Logoff();