Outlook service is not killed after used by my application

R

Rui Oliveira

I am using the code below, to send an email from my application.
After send email or close the email windows, the OUTLOOK service in
background is not closed. Why? What I am doing wrong?
And when I try to open Outlook, Outlook gives an error because there is a
service running.
I just what popup email dialog with some information from my application,
user must complete email and click in send button to send email. When user
sends email the email dialog is closed, and is suppose the outlook service to
be killed. But that is not happening, the service still running after send
email.
Thanks.
Rui Oliveira


_Application olApp;
Attachments myAttachments;
if(!olApp.CreateDispatch("Outlook.Application"))
{
return FALSE;
}
// 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));
myAttachments = olMail.GetAttachments();
//olMail.SetBodyFormat(1);

for(int i=0; i<icl_attachmentsList.GetCount(); i++)
{
COleVariant oAttachLocation(icl_attachmentsList);
myAttachments.Add(oAttachLocation, covOptional, covOptional, covOptional);
}
olMail.SetBody(is_mailBody);
olMail.SetSubject(is_mailSubject);
// Send the message!
olMail.Display(COleVariant((short)FALSE));

olNs.Logoff();
olNs.ReleaseDispatch();
olNs.DetachDispatch();
olApp.ReleaseDispatch();
olApp.DetachDispatch();
 

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