Article View: borland.public.cppbuilder.internet.web
Article #978Re: How display MAPIMAIL
From: RS
Date: Fri, 03 Mar 2006 18:37
Date: Fri, 03 Mar 2006 18:37
272 lines
9648 bytes
9648 bytes
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)" <no.spam@no.spam.com> a οΏ½crit dans le message de news:
4407681b$1@newsgroups.borland.com...
>
> "RS" <rs.reloaded@wanadoo.fr> wrote in message
> news:44073e03$1@newsgroups.borland.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("me@myaddress.com"),
> TEXT("you@youraddress.com"),
> TEXT("Here is the Subject"),
> TEXT("Here is the Body Text"),
> Files,
> 2);
> }
>
> //--------------------------------------------------------------------------
> -
>
>
> Gambit
>
>
Technical Details
Message-ID:
<44088be9@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.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> <44064ed2$1@newsgroups.borland.com> <44073e03$1@newsgroups.borland.com> <4407681b$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> <440602dc$1@newsgroups.borland.com> <44064ed2$1@newsgroups.borland.com> <44073e03$1@newsgroups.borland.com> <4407681b$1@newsgroups.borland.com> Subject: Re: How display MAPIMAIL Date: Fri, 3 Mar 2006 19:37:00 +0100 Lines: 274 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.36.42 Message-ID: <44088be9@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1141410793 83.196.36.42 (3 Mar 2006 10:33:13 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.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