Board index » cppbuilder » How display MAPIMAIL

How display MAPIMAIL


2006-02-27 03:43:37 AM
cppbuilder93
Hello !
How to display MAPIMAIL window with attachment ? (Microsoft Outlook or
Outlook Express new message window)
Like this :
www.hawaii.rr.com/rrhelp/email/PC/IE5/addressbook/media/6click%20to%20from%20new%20message%20window.gif
Thanks ;)
 
 

Re:How display MAPIMAIL

"RS" < XXXX@XXXXX.COM >wrote in message
Quote
How to display MAPIMAIL window with attachment ?
(Microsoft Outlook or Outlook Express new message window)
Look at the MapiSendMail() function.
Gambit
 

Re:How display MAPIMAIL

?"RS" < XXXX@XXXXX.COM >Ýãñáøå óô?ìÞíõìá
Quote
Hello !

How to display MAPIMAIL window with attachment ? (Microsoft Outlook or
Outlook Express new message window)

Like this :

www.hawaii.rr.com/rrhelp/email/PC/IE5/addressbook/media/6click%20to%20from%20new%20message%20window.gif
Maybe this can help you
char* dest = "mailto : XXXX@XXXXX.COM "; // Remove the spaces form
dest string after mailto
ShellExecute(this->Handle,"open",dest,"","",SW_SHOWNORMAL);
-minas
 

{smallsort}

Re:How display MAPIMAIL

Hi,
Many thanks for your answers, but :
- The MapiSendMail() function doesn't exist (Borland C++ Builder 6)
( with : include <mapi.h>)
- The "mailto :" function don't allow the attachment.
Another suggestion ?
Thanks a lot.
RS.
"HF" <(min_charATyahooPUTADOTgr)(HellenicFire)>a écrit dans le message de
Quote

?"RS" < XXXX@XXXXX.COM >Ýãñáøå óô?ìÞíõìá
news: XXXX@XXXXX.COM ...
>Hello !
>
>How to display MAPIMAIL window with attachment ? (Microsoft Outlook or
>Outlook Express new message window)
>
>Like this :
>
>www.hawaii.rr.com/rrhelp/email/PC/IE5/addressbook/media/6click%20to%20from%20new%20message%20window.gif

Maybe this can help you
char* dest = "mailto : XXXX@XXXXX.COM "; // Remove the spaces
form dest string after mailto

ShellExecute(this->Handle,"open",dest,"","",SW_SHOWNORMAL);


-minas

 

Re:How display MAPIMAIL

Hello,
I'm finally finding the following code :
But I don't know how I can integrated an attachment ! (for example :
Edit1->Text = "c:\file.txt")
And how can I integrated the recipient email address (Edit2->Text = "
XXXX@XXXXX.COM ")
//-----------------------------------------
TART -----------------------------------
TMapiMessage MapiMessage;
Cardinal MError;
MapiMessage.ulReserved = 0;
MapiMessage.lpszSubject = "this is a test";
MapiMessage.lpszNoteText = RichEdit1->Lines->Text.c_str(); //
RichEdit1 contains the body message
MapiMessage.lpszMessageType = NULL;
MapiMessage.lpszDateReceived = NULL;
MapiMessage.lpszConversationID = NULL;
MapiMessage.flFlags = 0;
MapiMessage.lpOriginator = NULL;
MapiMessage.nRecipCount = 0;
MapiMessage.lpRecips = NULL; // How to put Edit2->Text on lpRecips
???
MapiMessage.nFileCount = NULL;
MapiMessage.lpFiles = NULL; // How to put Edit1->Text on lpFiles
???
MError = MapiSendMail(0, reinterpret_cast<unsigned
int>(Application->Handle),
MapiMessage, MAPI_DIALOG | MAPI_LOGON_UI |
MAPI_NEW_SESSION, 0);
if (MError)
ShowMessage("Error !");
//-----------------------------
END -----------------------------------------------
I search on the net, but I don't find the solution !
Thanks ;)
RS
I'm using Borland C++ Builder 6 enterprise
"RS" < XXXX@XXXXX.COM >a écrit dans le message de news:
XXXX@XXXXX.COM ...
Quote
Hello !

How to display MAPIMAIL window with attachment ? (Microsoft Outlook or
Outlook Express new message window)

Like this :

www.hawaii.rr.com/rrhelp/email/PC/IE5/addressbook/media/6click%20to%20from%20new%20message%20window.gif


Thanks ;)





 

Re:How display MAPIMAIL

?"RS" < XXXX@XXXXX.COM >Ýãñáøå óô?ìÞíõìá
Quote
Hello,
I'm finally finding the following code :

But I don't know how I can integrated an attachment ! (for example :
Edit1->Text = "c:\file.txt")
And how can I integrated the recipient email address (Edit2->Text = "
XXXX@XXXXX.COM ")

A MapiFileDesc structure holds information about a message attachment
so add this
MapiFileDesc tmp={0};
tmp.lpszPathName= "C:\\yourFile.txt";
tmp.nPosition = -1;
tmp.lpszFileName ="";
A MapiRecipDesc structure holds information about a message sender or
recipient
so add the following for recipient (you can use an array for more
recipients)
MapiRecipDesc rec={0};
rec.ulRecipClass = MAPI_TO;
rec.lpszAddress = "SMTP: XXXX@XXXXX.COM ";
Quote
TMapiMessage MapiMessage;
Instead
MapiMessage MapiMessage;
Quote
Cardinal MError;

MapiMessage.ulReserved = 0;
MapiMessage.lpszSubject = "this is a test";
MapiMessage.lpszNoteText = RichEdit1->Lines->Text.c_str(); //
RichEdit1 contains the body message
MapiMessage.lpszMessageType = NULL;
MapiMessage.lpszDateReceived = NULL;
MapiMessage.lpszConversationID = NULL;
MapiMessage.flFlags = 0;
MapiMessage.lpOriginator = NULL;
MapiMessage.nRecipCount = 0;
MapiMessage.lpRecips = NULL; // How to put Edit2->Text on
lpRecips ???
MapiMessage.nFileCount = NULL;
MapiMessage.lpFiles = NULL; // How to put Edit1->Text on
lpFiles
Instead
MapiMessage.nRecipCount = 1;
MapiMessage.lpRecips = &rec;
MapiMessage.nFileCount = 1;
MapiMessage.lpFiles = &tmp
Quote
MError = MapiSendMail(0, reinterpret_cast<unsigned
int>(Application->Handle),
MapiMessage, MAPI_DIALOG | MAPI_LOGON_UI |
MAPI_NEW_SESSION, 0);
Instead you can use
MError = MAPISendMail(0L,0L , &MapiMessage,MAPI_DIALOG, 0L);
//******** Put also this *******//
MAPIFreeBuffer(&tmp);
MAPIFreeBuffer(&rec);
//****************
Quote
if (MError)
ShowMessage("Error !");
I hope ididn't miss something :-)
-minas
 

Re:How display MAPIMAIL

"RS" < XXXX@XXXXX.COM >wrote in message
Quote
- The MapiSendMail() function doesn't exist (Borland C++ Builder 6)
Yes, it does.
Quote
with : include <mapi.h>
Did you try looking in that file yet? I assure you that MAPISendMail() is
in it.
Gambit
 

Re:How display MAPIMAIL

"RS" < XXXX@XXXXX.COM >wrote in message
Quote
But I don't know how I can integrated an attachment !
I am guessing that you did not read the documentation yet, correct?
MAPISendMail() is in the Win32 API documentation:
MAPISendMail
msdn.microsoft.com/library/en-us/mapi/html/4cb46e35-cd8f-4c6a-9a10-2a3f63e84ecd.asp
MapiMessage
msdn.microsoft.com/library/en-us/mapi/html/8dce3399-176b-48c9-acff-ccdeedbc8033.asp
Quote
MapiMessage.lpszNoteText = RichEdit1->Lines->Text.c_str();
That code will not work like that. You are retreiving a char* pointer for a
temporary AnsiString that goes out of scope immediately, thus leaving the
MAPI structure pointing to invalid memory. You will need to make a copy of
the Text in order to keep the data in memory long enough for MAPI to use it.
The easiest way is to just use an AnsiString variable that remains in scope,
ie:
AnsiString body = RichEdit1->Lines->Text;
MapiMessage.lpszNoteText = body.c_str();
Quote
MapiMessage.nRecipCount = 0;
MapiMessage.lpRecips = NULL; // How to put Edit2->Text on
lpRecips
???
Had you read the documentation, you would see that the lpRecips member is an
array of MapiRecipDesc structures. So, to specify a single recipient, you
simply declare an instance of the MapiRecipDesc structure, fill it in as
needed, and then assign its memory pointer to the lpRecips member, ie:
AnsiString addr = "SMTP:" + Edit2->Text;
MapiRecipDesc recip = {0};
recip.ulRecipClass = MAPI_TO;
recip.lpszAddress = addr.c_str();
MapiMessage.nRecipCount = 1;
MapiMessage.lpRecips = &recip;
Quote
MapiMessage.nFileCount = NULL;
MapiMessage.lpFiles = NULL; // How to put Edit1->Text on
lpFiles
???
The same applies for files as well, except with the MapiFileDesc structure
instead:
AnsiString path = Edit1->Text;
AnsiString filename = ExtractFileName(path);
MapiFileDesc file = {0};
file.nPosition = 0xFFFFFFFF;
recip.lpszPathName = path.c_str();
recip.lpszFileName = filename.c_str();
MapiMessage.nFileCount = 1;
MapiMessage.lpFiles = &file;
Gambit
 

Re:How display MAPIMAIL

"HF" <(min_charATyahooPUTADOTgr)(HellenicFire)>wrote in message
Quote
//******** Put also this *******//
MAPIFreeBuffer(&tmp);
MAPIFreeBuffer(&rec);
//****************
Do not do that. In the code you provided, none of the structure members are
dynamically allocated, so there is nothing to free. The only time you
should ever call MAPIFreeBuffer() is when freeing memory that the MAPI
system itself allocated, which is not the case here. The only functions
that allocate memory which has to be freed by the user's code is
MAPIReadMail(), MAPIAddress(), and MAPIResolveName().
Gambit
 

Re:How display MAPIMAIL

?"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >Ýãñáøå óô?ìÞíõìá
Quote

"HF" <(min_charATyahooPUTADOTgr)(HellenicFire)>wrote in message
news: XXXX@XXXXX.COM ...

>//******** Put also this *******//
>MAPIFreeBuffer(&tmp);
>MAPIFreeBuffer(&rec);
>//****************

Do not do that. In the code you provided, none of the structure members
are
Thanks, you are right :-)
 

Re:How display MAPIMAIL

YES !!!
Many thanks to HF and Remy Lebeau, very very good !!
My goal is to appear the MAPI Windows (Outlook Express), and the user can
modify subject and body, and can press Send button.
I'm finally finding this following code
This code can open Outlook Express (if he's default MAPI software) with 2
attachments (c:\test.pdf and c:\test.txt)
This code works perfectly if I put 0 instead of MAPI_DIALOG in this function
:
pfnSendMail(lHnd,0, &mapimsg,MAPI_DIALOG,0);
the mail is send directly with no confirmation.
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.
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.
I espere that I express myself clearly ! lol (excuse me ! I'm French ! lol)
This is my code :
//------------------------------------------------------------------
LPMAPISENDMAIL pfnSendMail;
MapiRecipDesc rdOriginator;
MapiRecipDesc rdRecipient[1];
LPMAPILOGOFF pfnLogoff;
LPMAPILOGON pfnLogon;
MapiMessage mapimsg;
HINSTANCE hDll;
LHANDLE lHnd;
MapiFileDesc mapifiledesc[2];
if(NULL == (hDll = LoadLibrary(TEXT("MAPI32.DLL"))))
{
_tprintf(TEXT("could not load mapi32.dll, ErrorCode: %u"),
GetLastError());
}
pfnLogon = (LPMAPILOGON)GetProcAddress(hDll, "MAPILogon");
pfnLogoff = (LPMAPILOGOFF)GetProcAddress(hDll, "MAPILogoff");
pfnSendMail = (LPMAPISENDMAIL)GetProcAddress(hDll, "MAPISendMail");
pfnLogon(0, NULL, NULL, 0, 0, &lHnd);
mapimsg.ulReserved = 0;
mapimsg.lpszSubject = "Here the subject";
mapimsg.lpszNoteText = "Here is the Body Text";
mapimsg.lpszMessageType = NULL;
mapimsg.lpszDateReceived = NULL;
mapimsg.lpszConversationID = NULL;
mapimsg.flFlags = MAPI_UNREAD;
mapimsg.lpOriginator = &rdOriginator;
mapimsg.nRecipCount = NUM_ELEMENTS(rdRecipient);
mapimsg.lpRecips = rdRecipient;
mapimsg.nFileCount = 2;
mapimsg.lpFiles = &mapifiledesc[0];
rdOriginator.ulReserved = 0;
rdOriginator.ulRecipClass = MAPI_ORIG;
rdOriginator.lpszName = "rdOriginator";
rdOriginator.lpszAddress = " XXXX@XXXXX.COM "; // Expediteur
rdOriginator.ulEIDSize = 0;
rdOriginator.lpEntryID = NULL;
rdRecipient[0].ulReserved = 0;
rdRecipient[0].ulRecipClass = MAPI_TO;
rdRecipient[0].lpszName = NULL;
rdRecipient[0].lpszAddress = " XXXX@XXXXX.COM "; //
Destinataire
rdRecipient[0].ulEIDSize = 0;
rdRecipient[0].lpEntryID = NULL;
mapifiledesc[0].ulReserved = 0;
mapifiledesc[0].flFlags = 0;
mapifiledesc[0].nPosition = -1;
mapifiledesc[0].lpszPathName = "C:\\test.txt";
mapifiledesc[0].lpszFileName = "test.txt";
mapifiledesc[0].lpFileType = 0;
mapifiledesc[1].ulReserved = 0;
mapifiledesc[1].flFlags = 0;
mapifiledesc[1].nPosition = -1;
mapifiledesc[1].lpszPathName = "C:\\test.pdf";
mapifiledesc[1].lpszFileName = "test.pdf";
mapifiledesc[1].lpFileType = 0;
pfnSendMail(lHnd,0, &mapimsg,MAPI_DIALOG,0);
pfnLogoff(lHnd, 0, 0, 0);
FreeLibrary(hDll);
//----------------------------------------------------------------------------
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >a écrit dans le message de news:
4404fe85$ XXXX@XXXXX.COM ...
Quote

"RS" < XXXX@XXXXX.COM >wrote in message
news:4404bbf5$ XXXX@XXXXX.COM ...

>But I don't know how I can integrated an attachment !

I am guessing that you did not read the documentation yet, correct?
MAPISendMail() is in the Win32 API documentation:

MAPISendMail

msdn.microsoft.com/library/en-us/mapi/html/4cb46e35-cd8f-4c6a-9a10-2a3f63e84ecd.asp

MapiMessage

msdn.microsoft.com/library/en-us/mapi/html/8dce3399-176b-48c9-acff-ccdeedbc8033.asp


>MapiMessage.lpszNoteText = RichEdit1->Lines->Text.c_str();

That code will not work like that. You are retreiving a char* pointer for
a
temporary AnsiString that goes out of scope immediately, thus leaving the
MAPI structure pointing to invalid memory. You will need to make a copy
of
the Text in order to keep the data in memory long enough for MAPI to use
it.
The easiest way is to just use an AnsiString variable that remains in
scope,
ie:

AnsiString body = RichEdit1->Lines->Text;
MapiMessage.lpszNoteText = body.c_str();

>MapiMessage.nRecipCount = 0;
>MapiMessage.lpRecips = NULL; // How to put Edit2->Text on
lpRecips
>???

Had you read the documentation, you would see that the lpRecips member is
an
array of MapiRecipDesc structures. So, to specify a single recipient, you
simply declare an instance of the MapiRecipDesc structure, fill it in as
needed, and then assign its memory pointer to the lpRecips member, ie:

AnsiString addr = "SMTP:" + Edit2->Text;

MapiRecipDesc recip = {0};
recip.ulRecipClass = MAPI_TO;
recip.lpszAddress = addr.c_str();

MapiMessage.nRecipCount = 1;
MapiMessage.lpRecips = &recip;

>MapiMessage.nFileCount = NULL;
>MapiMessage.lpFiles = NULL; // How to put Edit1->Text on
lpFiles
>???

The same applies for files as well, except with the MapiFileDesc structure
instead:

AnsiString path = Edit1->Text;
AnsiString filename = ExtractFileName(path);

MapiFileDesc file = {0};
file.nPosition = 0xFFFFFFFF;
recip.lpszPathName = path.c_str();
recip.lpszFileName = filename.c_str();

MapiMessage.nFileCount = 1;
MapiMessage.lpFiles = &file;


Gambit


 

Re:How display MAPIMAIL

"RS" < XXXX@XXXXX.COM >wrote in message
Quote
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.
Quote
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
 

Re:How display MAPIMAIL

Many Thanks Remy,
But I Have problem, can you put the full source code for my situation ?
My problem is : I don't know who I put your code !! before what ? after
what ? to replace something ? I don't know ...
I'm sorry, I'm not a big professionnal of C++ !!! lol
I Have error :
1) [C++ Error] Unit1.cpp(411): E2108 Improper use of typedef 'LPTSTR'
LPTSTR GetFileName(LPTSTR szPathName)
My first code is on a simple button click.
Do I have create void TForm1:GetFileName() ??? and void
TForm1::SendMapiMessage() ???
Thanks a lot, you are very very ... good !!! You advanced to me 10
years!!!
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >a écrit dans le message de news:
44064ed2$ XXXX@XXXXX.COM ...
Quote

"RS" < XXXX@XXXXX.COM >wrote in message
news:440602dc$ XXXX@XXXXX.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


 

Re:How display MAPIMAIL

"RS" < XXXX@XXXXX.COM >wrote in message
Quote
But I Have problem
Please be more specific.
Quote
can you put the full source code for my situation ?
The code I gave you is a direct copy-paste from the test project I wrote for
this discussion, which works fine when I run it as-is.
Quote
I don't know who I put your code !!
You simply replace the code you showed earlier with the code I gave you.
What exactly is so hard about that?
Quote
I Have error :
You probably put the code in the wrong place. GetFileName() is a standalone
function. It cannot be placed inside another function, which is what you
are likely doing.
Quote
My first code is on a simple button click.
Here is the FULL code I used for testing:
--- Unit1.h---
//--------------------------------------------------------------------------
-
#ifndef MapiSendMailFormH
#define MapiSendMailFormH
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif
//--------------------------------------------------------------------------
-
--- Unit1.cpp ---
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <mapi.h>
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
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)
{
TCHAR szMsg[64];
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 )
{
wsprintf(szMsg, TEXT("could not send mapi32
message, ErrorCode: %u"), err);
MessageBox(NULL, szMsg, TEXT("Error"), MB_OK);
}
err = pfnLogoff(lHnd, (ULONG) hWnd, 0, 0);
if( SUCCESS_SUCCESS != err )
{
wsprintf(szMsg, TEXT("could not log out of
mapi32, ErrorCode: %u"), err);
MessageBox(NULL, szMsg, TEXT("Error"), MB_OK);
}
}
else
{
wsprintf(szMsg, TEXT("could not log in to mapi32,
ErrorCode: %u"), err);
MessageBox(NULL, szMsg, TEXT("Error"), MB_OK);
}
if( mapifiledesc )
free(mapifiledesc);
}
else
MessageBox(NULL, TEXT("could not allocate memory for
attachments"), TEXT("Error"), MB_OK);
}
else
{
MessageBox(NULL, TEXT("could not load mapi32 functions"),
TEXT("Error"), MB_OK);
}
FreeLibrary(hDll);
}
else
{
wsprintf(szMsg, TEXT("could not load mapi32.dll, ErrorCode:
%u"), GetLastError());
MessageBox(NULL, szMsg, TEXT("Error"), MB_OK);
}
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
LPTSTR Files[2] = {
TEXT("C:\\autoexec.bat"),
TEXT("C:\\config.sys")
};
SendMapiMessage(
Application->Handle,
TEXT(" XXXX@XXXXX.COM "),
TEXT(" XXXX@XXXXX.COM "),
TEXT("Here is the Subject"),
TEXT("Here is the Body Text"),
Files,
2);
}
//--------------------------------------------------------------------------
-
Gambit
 

Re:How display MAPIMAIL

Remy (Gambit) : you are the king !!
It works perfectly with outlook express !!!
Thank you very very very ... (very x 1000) much !!!! lol
But this code doesn't run if Microsoft Outlook 2003 is default mapi software
:
Could not send mapi 32 message : ErrorCode : 11
It works perfectly with Outlook express 6.
My config : Borland C++ Builder 6 , PC XP Pro SP2, Office 2003
Many many many thanks !!!
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >a écrit dans le message de news:
4407681b$ XXXX@XXXXX.COM ...
Quote

"RS" < XXXX@XXXXX.COM >wrote in message
news:44073e03$ XXXX@XXXXX.COM ...

>But I Have problem

Please be more specific.

>can you put the full source code for my situation ?

The code I gave you is a direct copy-paste from the test project I wrote
for
this discussion, which works fine when I run it as-is.

>I don't know who I put your code !!

You simply replace the code you showed earlier with the code I gave you.
What exactly is so hard about that?

>I Have error :

You probably put the code in the wrong place. GetFileName() is a
standalone
function. It cannot be placed inside another function, which is what you
are likely doing.

>My first code is on a simple button click.

Here is the FULL code I used for testing:

--- Unit1.h---


//--------------------------------------------------------------------------
-

#ifndef MapiSendMailFormH
#define MapiSendMailFormH

//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>

//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};

//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;

//--------------------------------------------------------------------------
-
#endif

//--------------------------------------------------------------------------
-


--- Unit1.cpp ---

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <mapi.h>

//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}

//--------------------------------------------------------------------------
-
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)
{
TCHAR szMsg[64];

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 )
{
wsprintf(szMsg, TEXT("could not send mapi32
message, ErrorCode: %u"), err);
MessageBox(NULL, szMsg, TEXT("Error"), MB_OK);
}

err = pfnLogoff(lHnd, (ULONG) hWnd, 0, 0);
if( SUCCESS_SUCCESS != err )
{
wsprintf(szMsg, TEXT("could not log out of
mapi32, ErrorCode: %u"), err);
MessageBox(NULL, szMsg, TEXT("Error"), MB_OK);
}
}
else
{
wsprintf(szMsg, TEXT("could not log in to mapi32,
ErrorCode: %u"), err);
MessageBox(NULL, szMsg, TEXT("Error"), MB_OK);
}

if( mapifiledesc )
free(mapifiledesc);
}
else
MessageBox(NULL, TEXT("could not allocate memory for
attachments"), TEXT("Error"), MB_OK);
}
else
{
MessageBox(NULL, TEXT("could not load mapi32 functions"),
TEXT("Error"), MB_OK);
}

FreeLibrary(hDll);
}
else
{
wsprintf(szMsg, TEXT("could not load mapi32.dll, ErrorCode:
%u"), GetLastError());
MessageBox(NULL, szMsg, TEXT("Error"), MB_OK);
}
}

//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
LPTSTR Files[2] = {
TEXT("C:\\autoexec.bat"),
TEXT("C:\\config.sys")
};

SendMapiMessage(
Application->Handle,
TEXT(" XXXX@XXXXX.COM "),
TEXT(" XXXX@XXXXX.COM "),
TEXT("Here is the Subject"),
TEXT("Here is the Body Text"),
Files,
2);
}

//--------------------------------------------------------------------------
-


Gambit