πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11128

MAPI problem, don't send the e-Mail JUST save it in the 'outgoing' folder of the mailclient...

#11128
From: Oren Halvani
Date: Sun, 22 Feb 2004 23:15
141 lines
5406 bytes
hi dear builders,

the following snip sends a e-mail directly with the installed mail-client
how can I avoid the direct sending...? I just want the e-Mail to be stored
in
the "outgoing" folder of the mail client (outlook or similar...) NOT to be
send
now..

what do I ned to change in my code...?


Oren

/***********************************************/
#include <mapi.h>


bool MapiSendMail(TStrings* pslRecipients, TStrings* pslCcRecipients,
AnsiString slSubject, AnsiString slText, TStrings* pslAttachments)
{
if(!pslRecipients || !pslRecipients->Count)
return false;
bool blRetVal = true;
HINSTANCE hMapi=LoadLibrary("MAPI32.DLL");
if(hMapi)
{
LPMAPILOGON pfMapiLogon= (LPMAPILOGON)
GetProcAddress(hMapi,"MAPILogon");
LPMAPILOGOFF pfMapiLogoff=(LPMAPILOGOFF)
GetProcAddress(hMapi,"MAPILogoff");
LPMAPISENDMAIL pfMapiSendMail=(LPMAPISENDMAIL)
GetProcAddress(hMapi,"MAPISendMail");
// Funktionszeiger auf NULL prοΏ½fen:
blRetVal = pfMapiLogon && pfMapiLogoff && pfMapiSendMail;

LHANDLE hSession = NULL;
if(blRetVal) blRetVal = ((*pfMapiLogon)(0, NULL, NULL, MAPI_LOGON_UI, 0,
&hSession) == SUCCESS_SUCCESS);

if(blRetVal)
{

int ilRecCount = pslRecipients->Count;

if(pslCcRecipients && pslCcRecipients->Count)
ilRecCount += pslCcRecipients->Count;

MapiRecipDesc* pstRecDesc = new MapiRecipDesc[ilRecCount];
AnsiString slAddress;

for(int ilLine = 0; ilLine < pslRecipients->Count; ilLine++)
{
memset(&pstRecDesc[ilLine], 0, sizeof(MapiRecipDesc));
slAddress = pslRecipients->Strings[ilLine];
pstRecDesc[ilLine].ulRecipClass = MAPI_TO;
pstRecDesc[ilLine].lpszName = AnsiString("SMTP:"+slAddress).c_str();
pstRecDesc[ilLine].lpszName = new char[slAddress.Length() + 1];
strcpy(pstRecDesc[ilLine].lpszName,slAddress.c_str());
pstRecDesc[ilLine].lpszAddress = new char[slAddress.Length() + 6];
strcpy(pstRecDesc[ilLine].lpszAddress,("SMTP:"+slAddress).c_str());
}
int ilIndex = 0;

for(int ilLine = 0; pslCcRecipients && ilLine <
pslCcRecipients->Count; ilLine++)
{
ilIndex = pslRecipients->Count+ilLine;
memset(&pstRecDesc[ilIndex], 0, sizeof(MapiRecipDesc));
slAddress = pslCcRecipients->Strings[ilLine];
pstRecDesc[ilIndex].ulRecipClass = MAPI_CC;
pstRecDesc[ilIndex].lpszName = new char[slAddress.Length() + 1];
strcpy(pstRecDesc[ilIndex].lpszName,slAddress.c_str());
pstRecDesc[ilIndex].lpszAddress = new char[slAddress.Length() + 6];
strcpy(pstRecDesc[ilIndex].lpszAddress,("SMTP:"+slAddress).c_str());
}
MapiFileDesc* pstFilesDesc = NULL;
if(pslAttachments && pslAttachments->Count)
{
pstFilesDesc = new MapiFileDesc[pslAttachments->Count];
AnsiString slFullPath, slFileName;
for(int ilLine = 0; ilLine < pslAttachments->Count; ilLine++)
{
memset(&pstFilesDesc[ilLine], 0, sizeof(MapiFileDesc));
slFullPath = pslAttachments->Strings[ilLine];
slFileName = slFullPath.SubString(slFullPath.LastDelimiter("\\:")+1
<file://\\:>,
slFullPath.Length());
pstFilesDesc[ilLine].nPosition = (ULONG) -1;
pstFilesDesc[ilLine].lpszPathName = new char[slFullPath.Length() + 1];
pstFilesDesc[ilLine].lpszFileName = new char[slFileName.Length() + 1];
strcpy(pstFilesDesc[ilLine].lpszPathName, slFullPath.c_str());
strcpy(pstFilesDesc[ilLine].lpszFileName, slFileName.c_str());
}
}
MapiMessage MapiMsg = {
0,slSubject.c_str(),slText.c_str(),NULL,NULL,NULL,0,NULL,0,0,0,0 };
MapiMsg.nRecipCount = (ULONG)ilRecCount;
MapiMsg.lpRecips = (lpMapiRecipDesc)(pstRecDesc);
if(pstFilesDesc)
{
MapiMsg.nFileCount = (ULONG) pslAttachments->Count;
MapiMsg.lpFiles = (lpMapiFileDesc)(pstFilesDesc);
}
blRetVal = (*pfMapiSendMail)(hSession,0,&MapiMsg, MAPI_LOGON_UI ,0) ==
SUCCESS_SUCCESS;

if(pstRecDesc)
{
for(int ilEntry=0; ilEntry < ilRecCount; ilEntry++)
{
delete [] pstRecDesc[ilEntry].lpszAddress;
delete [] pstRecDesc[ilEntry].lpszName;
}
delete [] pstRecDesc;
}

if(pstFilesDesc)
{
for (int ilEntry=0; ilEntry < pslAttachments->Count; ilEntry++)
{
delete [] pstFilesDesc[ilEntry].lpszPathName;
delete [] pstFilesDesc[ilEntry].lpszFileName;
}
delete [] pstFilesDesc;
}
}
(*pfMapiLogoff)(hSession,0,0,0);
FreeLibrary(hMapi);
return blRetVal;
}
else return false;
}
void __fastcall TfrmEmail_Config::Button1Click(TObject *Sender)
{
TStringList* pslAddresses = new TStringList();
pslAddresses->Add("abc@def.gh <mailto:abc@def.gh>");
if(!MapiSendMail(pslAddresses, NULL, "Hello...", Memo1->Text, NULL))
ShowMessage("error while sending mail...!");
delete pslAddresses;
}
Technical Details
Message-ID: <40393810@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10cc67,8da98ed36c72cc3f
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-02-22 15:39:38 PST
Reply-To: "Oren Halvani" <sharon78@freenet.de>
From: "Oren Halvani" <sharon78@freenet.de>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: MAPI problem, don't send the e-Mail JUST save it in the 'outgoing' folder of the mailclient...
Date: Mon, 23 Feb 2004 00:15:22 +0100
Lines: 143
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 213.6.46.38
Message-ID: <40393810@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1077491728 213.6.46.38 (22 Feb 2004 15:15:28 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail