Board index » cppbuilder » How display MAPIMAIL
RS
![]() CBuilder Developer |
RS
![]() CBuilder Developer |
How display MAPIMAIL2006-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 ;) |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2006-02-28 04:27:11 AM
Re:How display MAPIMAIL
"RS" < XXXX@XXXXX.COM >wrote in message
QuoteHow to display MAPIMAIL window with attachment ? |
HF
![]() CBuilder Developer |
2006-02-28 07:10:01 AM
Re:How display MAPIMAIL
?"RS" < XXXX@XXXXX.COM >Ýãñáøå óô?ìÞíõìá
QuoteHello ! dest string after mailto ShellExecute(this->Handle,"open",dest,"","",SW_SHOWNORMAL); -minas {smallsort} |
RS
![]() CBuilder Developer |
2006-03-01 04:21:37 AM
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
![]() CBuilder Developer |
2006-03-01 05:12:53 AM
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 ... QuoteHello ! |
HF
![]() CBuilder Developer |
2006-03-01 06:58:55 AM
Re:How display MAPIMAIL
?"RS" < XXXX@XXXXX.COM >Ýãñáøå óô?ìÞíõìá
QuoteHello, 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 "; QuoteTMapiMessage MapiMessage; QuoteCardinal MError; MapiMessage.lpRecips = &rec; MapiMessage.nFileCount = 1; MapiMessage.lpFiles = &tmp QuoteMError = MapiSendMail(0, reinterpret_cast<unsigned //******** Put also this *******// MAPIFreeBuffer(&tmp); MAPIFreeBuffer(&rec); //**************** Quoteif (MError) |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2006-03-01 09:34:43 AM
Re:How display MAPIMAIL
"RS" < XXXX@XXXXX.COM >wrote in message
Quote- The MapiSendMail() function doesn't exist (Borland C++ Builder 6) Quotewith : include <mapi.h> Gambit |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2006-03-01 09:54:02 AM
Re:How display MAPIMAIL
"RS" < XXXX@XXXXX.COM >wrote in message
QuoteBut I don't know how I can integrated an attachment ! 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 QuoteMapiMessage.lpszNoteText = RichEdit1->Lines->Text.c_str(); 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(); QuoteMapiMessage.nRecipCount = 0; 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; QuoteMapiMessage.nFileCount = NULL; 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 |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2006-03-01 09:56:23 AM
Re:How display MAPIMAIL
"HF" <(min_charATyahooPUTADOTgr)(HellenicFire)>wrote in message
Quote//******** Put also this *******// 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 |
HF
![]() CBuilder Developer |
2006-03-01 04:59:34 PM
Re:How display MAPIMAIL
?"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >Ýãñáøå óô?ìÞíõìá
Quote
|
RS
![]() CBuilder Developer |
2006-03-02 04:27:41 AM
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
|
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2006-03-02 09:45:01 AM
Re:How display MAPIMAIL
"RS" < XXXX@XXXXX.COM >wrote in message
QuoteMy goal is not to send directly, I want the MAPI window to modify QuoteIf I Put MAPI_DIALOG instead of 0 in pfnSendMail(), the MAPI 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 |
RS
![]() CBuilder Developer |
2006-03-03 02:52:21 AM
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
|
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2006-03-03 05:49:09 AM
Re:How display MAPIMAIL
"RS" < XXXX@XXXXX.COM >wrote in message
QuoteBut I Have problem Quotecan you put the full source code for my situation ? QuoteI don't know who I put your code !! QuoteI Have error : are likely doing. QuoteMy first code is on a simple button click. //-------------------------------------------------------------------------- - #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 |
RS
![]() CBuilder Developer |
2006-03-04 02:37:00 AM
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
|