Add a attach file to an email in C++

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();
 
J

Jonathan Arnold

Rui said:
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?

Search MSDN for "C++ Outlook" and you'll find an example that does
exactly this, IIRC.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top