Hey all,
I am trying to use import to automate Outlook to send email for my CGI program.
However, outlook stays in memory after my program is finished and my program
got stuck with outlook too, can anybody tell me why and how to solve it?
Thanks a lot and the following is my code for sending email:
void Sendfile(){
try
{
_NameSpacePtr pNameSpace;
MAPIFolderPtr pOutbox;
_ItemsPtr pOutboxItems;
_MailItemPtr pNewMail;
AttachmentsPtr pAttachments;
RecipientsPtr pRecipients;
char eachfile[100];
char eachemail[100];
char eachcustmail[100];
int pos;
//fileLocation, set to 150 character lenght
char filelocat[250];
// Create an Outlook.Application pointer.
_ApplicationPtr pApp("Outlook.Application"
// Create NameSpace pointer.
pNameSpace = pApp->GetNamespace(L"MAPI"
// Logon in OutLook
pNameSpace->Logon(LogonTo);
// Create pointer to the Outbox Folder.
pOutbox = pNameSpace->GetDefaultFolder(olFolderOutbox);
// Create pointer to the Messages Collection.
pOutboxItems = pOutbox->Items;
// Create pointer to a new message.
pNewMail = pOutboxItems->Add();
// Set the Subject of the message.
pNewMail->Subject=subject;
// Set the Text of the message.
pNewMail->Body=body;
// Set the BCC address (already define in the header file)
pNewMail->BCC=BCC;
// Create pointer to the Attachments collection.
pAttachments = pNewMail->Attachments;
//Loop for Attachment for each file
pos=0;
while (pos <= (int)(strlen(filename)) ){
getStringNext(filename,pos,eachfile);
strcpy(filelocat,path);
strcat(filelocat,eachfile);
// printf("%s\n",filelocat);
if (IsExist_Notnull(filelocat)){
// Create new Attachment. path
pAttachments->Add(filelocat, (long)1, (long)(15000),
eachfile);
}
}//end while
// Create pointer to Recipients Collection.
pRecipients = pNewMail->Recipients;
//Loop for input string to extract mail addresses
pos=0;
while (pos <= (int)(strlen(custmail)) ){
getStringNext(custmail,pos,eachemail);
strcpy(eachcustmail,eachemail);
// printf("%s\n",filelocat);
// Add recipient.
pRecipients->Add(eachcustmail);
}//end while
// Resolve the recipient address.
pRecipients ->ResolveAll();
// Send the message.
pNewMail->Send();
// Logoff NameSpace.
pNameSpace->Logoff();
pApp->Quit();
return;
}
catch (_com_error &e)
{
dump_com_error(e);
return;
}
}//end
I am trying to use import to automate Outlook to send email for my CGI program.
However, outlook stays in memory after my program is finished and my program
got stuck with outlook too, can anybody tell me why and how to solve it?
Thanks a lot and the following is my code for sending email:
void Sendfile(){
try
{
_NameSpacePtr pNameSpace;
MAPIFolderPtr pOutbox;
_ItemsPtr pOutboxItems;
_MailItemPtr pNewMail;
AttachmentsPtr pAttachments;
RecipientsPtr pRecipients;
char eachfile[100];
char eachemail[100];
char eachcustmail[100];
int pos;
//fileLocation, set to 150 character lenght
char filelocat[250];
// Create an Outlook.Application pointer.
_ApplicationPtr pApp("Outlook.Application"
// Create NameSpace pointer.
pNameSpace = pApp->GetNamespace(L"MAPI"
// Logon in OutLook
pNameSpace->Logon(LogonTo);
// Create pointer to the Outbox Folder.
pOutbox = pNameSpace->GetDefaultFolder(olFolderOutbox);
// Create pointer to the Messages Collection.
pOutboxItems = pOutbox->Items;
// Create pointer to a new message.
pNewMail = pOutboxItems->Add();
// Set the Subject of the message.
pNewMail->Subject=subject;
// Set the Text of the message.
pNewMail->Body=body;
// Set the BCC address (already define in the header file)
pNewMail->BCC=BCC;
// Create pointer to the Attachments collection.
pAttachments = pNewMail->Attachments;
//Loop for Attachment for each file
pos=0;
while (pos <= (int)(strlen(filename)) ){
getStringNext(filename,pos,eachfile);
strcpy(filelocat,path);
strcat(filelocat,eachfile);
// printf("%s\n",filelocat);
if (IsExist_Notnull(filelocat)){
// Create new Attachment. path
pAttachments->Add(filelocat, (long)1, (long)(15000),
eachfile);
}
}//end while
// Create pointer to Recipients Collection.
pRecipients = pNewMail->Recipients;
//Loop for input string to extract mail addresses
pos=0;
while (pos <= (int)(strlen(custmail)) ){
getStringNext(custmail,pos,eachemail);
strcpy(eachcustmail,eachemail);
// printf("%s\n",filelocat);
// Add recipient.
pRecipients->Add(eachcustmail);
}//end while
// Resolve the recipient address.
pRecipients ->ResolveAll();
// Send the message.
pNewMail->Send();
// Logoff NameSpace.
pNameSpace->Logoff();
pApp->Quit();
return;
}
catch (_com_error &e)
{
dump_com_error(e);
return;
}
}//end