Exception when add attachment programmatically in vc++




I am writing a vc dll and I want to automate Outlook. I can create a new
mail item and send email no problem. The exception happens when I try to add
attachment to the mail item.

I am calling my dll from Java applet using JNI. Any suggestion why I am
getting exception when I try to add attachment and how to fix this problem.
Here is my code for adding attachment and send mail:

_NameSpace olNs(olApp.GetNamespace("MAPI"));
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
olNs.Logon(covOptional, covOptional, covOptional, covOptional);
_MailItem olMail(olApp.CreateItem(0));
olMail.SetTo("(e-mail address removed)");
olMail.SetSubject("Email subject");
Attachments atts = olMail.GetAttachments();
olMail.SetBody("Message text");

COleVariant covFilePath("C:\\email.txt");
atts.Add(covFilePath, covOptional, covOptional,covOptional); // fails here




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