πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #965

Re: How display MAPIMAIL

#965
From: RS
Date: Wed, 01 Mar 2006 20:27
174 lines
6936 bytes
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  = "adresse@expediteur.com"; // Expediteur
   rdOriginator.ulEIDSize    = 0;
   rdOriginator.lpEntryID    = NULL;

   rdRecipient[0].ulReserved   = 0;
   rdRecipient[0].ulRecipClass = MAPI_TO;
   rdRecipient[0].lpszName     = NULL;
   rdRecipient[0].lpszAddress  = "adresse@destinataire.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)" <no.spam@no.spam.com> a οΏ½crit dans le message de news: 
4404fe85$1@newsgroups.borland.com...
>
> "RS" <rs.reloaded@wanadoo.fr> wrote in message
> news:4404bbf5$1@newsgroups.borland.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
>
> http://msdn.microsoft.com/library/en-us/mapi/html/4cb46e35-cd8f-4c6a-9a10-2a3f63e84ecd.asp
>
>    MapiMessage
>
> http://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
>
> 
Technical Details
Message-ID: <440602dc$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.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
References: <4402040f@newsgroups.borland.com> <4404bbf5$1@newsgroups.borland.com> <4404fe85$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
From: "RS" <rs.reloaded@wanadoo.fr>
Newsgroups: borland.public.cppbuilder.internet.web
References: <4402040f@newsgroups.borland.com> <4404bbf5$1@newsgroups.borland.com> <4404fe85$1@newsgroups.borland.com>
Subject: Re: How display MAPIMAIL
Date: Wed, 1 Mar 2006 21:27:41 +0100
Lines: 176
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 83.196.170.82
Message-ID: <440602dc$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1141244636 83.196.170.82 (1 Mar 2006 12:23:56 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.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