Article View: borland.public.cppbuilder.internet.web
Article #966Re: How display MAPIMAIL
From: Remy Lebeau (TeamB)
Date: Thu, 02 Mar 2006 01:45
Date: Thu, 02 Mar 2006 01:45
138 lines
5836 bytes
5836 bytes
"RS" <rs.reloaded@wanadoo.fr> wrote in message
news:440602dc$1@newsgroups.borland.com...
> My goal is not to send directly, I want the MAPI window to modify
> subject and body, and click send button to send the mail.
Then you must specify the MAPI_DIALOG flag.
> If I Put MAPI_DIALOG instead of 0 in pfnSendMail(), the MAPI
> windows does correctly appear, and the attachments does appear
> correctly, but I can't modify subject, and I can't click to the send
button.
Despite what the documentation says, you need to specify a parent HWND to
MAPILogon(), MapiSendMail(), and MAPILogoff(). Then the popup window will
not be read-only. You can use the TApplication::Handle property for that.
Try this code:
LPTSTR GetFileName(LPTSTR szPathName)
{
LPTSTR szFileName = szPathName;
LPTSTR ptr = szPathName;
if( NULL != ptr )
{
while( 0 != *ptr )
{
if( TEXT('\\') == *ptr )
{
szFileName = ::CharNext(ptr);
ptr = szFileName;
}
else
ptr = ::CharNext(ptr);
}
if( 0 != *szFileName )
return szFileName;
}
return szPathName;
}
void SendMapiMessage(HWND hWnd, LPTSTR SenderAddr, LPTSTR RecipAddr,
LPTSTR Subject, LPTSTR Body, LPTSTR *Files, ULONG FileCount)
{
HINSTANCE hDll = ::LoadLibrary(TEXT("MAPI32.DLL"));
if( NULL != hDll )
{
LPMAPILOGON pfnLogon = (LPMAPILOGON) ::GetProcAddress(hDll,
TEXT("MAPILogon"));
LPMAPILOGOFF pfnLogoff = (LPMAPILOGOFF) ::GetProcAddress(hDll,
TEXT("MAPILogoff"));
LPMAPISENDMAIL pfnSendMail = (LPMAPISENDMAIL)
::GetProcAddress(hDll, TEXT("MAPISendMail"));
if( (NULL != pfnLogon) && (NULL != pfnLogoff) && (NULL !=
pfnSendMail) )
{
MapiFileDesc *mapifiledesc = NULL;
if( 0 != FileCount )
{
mapifiledesc = (MapiFileDesc*)
malloc(sizeof(MapiFileDesc) * FileCount);
if( NULL != mapifiledesc )
{
for(ULONG u = 0; u < FileCount; ++u)
{
mapifiledesc[u].nPosition = -1;
mapifiledesc[u].lpszPathName = Files[u];
mapifiledesc[u].lpszFileName =
GetFileName(Files[u]);
}
}
}
if( (0 == FileCount) || (NULL != mapifiledesc) )
{
LHANDLE lHnd;
ULONG err = pfnLogon((ULONG) hWnd, NULL, NULL,
MAPI_LOGON_UI, 0, &lHnd);
if( SUCCESS_SUCCESS == err )
{
MapiRecipDesc rdOriginator = {0};
rdOriginator.ulRecipClass = MAPI_ORIG;
rdOriginator.lpszAddress = SenderAddr;
MapiRecipDesc rdRecipient = {0};
rdRecipient.ulRecipClass = MAPI_TO;
rdRecipient.lpszAddress = RecipAddr;
MapiMessage mapimsg = {0};
mapimsg.lpszSubject = Subject;
mapimsg.lpszNoteText = Body;
mapimsg.lpOriginator = &rdOriginator;
mapimsg.nRecipCount = 1;
mapimsg.lpRecips = &rdRecipient;
mapimsg.nFileCount = FileCount;
mapimsg.lpFiles = mapifiledesc;
err = pfnSendMail(lHnd, (ULONG) hWnd, &mapimsg,
MAPI_DIALOG, 0);
if( SUCCESS_SUCCESS != err )
_tprintf(TEXT("could not send mapi32 message,
ErrorCode: %u"), err);
err = pfnLogoff(lHnd, (ULONG) hWnd, 0, 0);
if( SUCCESS_SUCCESS != err )
_tprintf(TEXT("could not log out of mapi32,
ErrorCode: %u"), err);
}
else
_tprintf(TEXT("could not log in to mapi32,
ErrorCode: %u"), err);
if( mapifiledesc )
free(mapifiledesc);
}
else
_tprintf(TEXT("could not allocate memory for
attachments"));
}
else
_tprintf(TEXT("could not load mapi32 functions"));
FreeLibrary(hDll);
}
else
_tprintf(TEXT("could not load mapi32.dll, ErrorCode: %u"),
GetLastError());
}
Gambit
Technical Details
Message-ID:
<44064ed2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4402040f@newsgroups.borland.com> <4404bbf5$1@newsgroups.borland.com> <4404fe85$1@newsgroups.borland.com> <440602dc$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,b415d4e666b19fd4 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.web References: <4402040f@newsgroups.borland.com> <4404bbf5$1@newsgroups.borland.com> <4404fe85$1@newsgroups.borland.com> <440602dc$1@newsgroups.borland.com> Subject: Re: How display MAPIMAIL Date: Wed, 1 Mar 2006 17:45:01 -0800 Lines: 140 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <44064ed2$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1141264082 68.69.17.41 (1 Mar 2006 17:48:02 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail