FUNCTION SendMailMapi() AS LOGIC /* This is a function to send email with Mapi The sample is provided 'As it is' and is free of any copyrights. For information or comments email to: cavo@marti.nl This and other samples can be found at 81.26.209.134/cavo Regards, Marc Verkade Marti BV - Naaldwijk - Netherlands Usage: Cut and Paste this functions in your App Change Vars cSubject,cText,cFile,aEmailAdresses Call function SendMailMapi() from anywhere within your program You can change the function and add some parameters for it! Revision Info: 01-05-2001 Initial creation of sample Mapi mail routines extracted from MC_Lib for VO */ LOCAL cSubject AS STRING LOCAL cText AS STRING LOCAL aEmail AS ARRAY LOCAL aFiles AS ARRAY LOCAL nSession AS DWORD LOCAL nResult AS DWORD LOCAL lRetVal AS LOGIC LOCAL n AS DWORD LOCAL nRecips AS DWORD LOCAL nFiles AS DWORD // MAPI structures, see Win32 API for structure info. LOCAL sMessage AS MAPIMessage LOCAL DIM aRecip[100] IS MAPIRecipDesc LOCAL DIM aFile[100] IS MAPIFileDesc // Init vars lRetVal:=TRUE cSubject :="This a an email test for VO and Mapi" cText :="Testing automatic creation of email" aFiles :={"C:\Autoexec.Bat"} aEmail :={"cavo@marti.nl"} nRecips := ALen( aEmail ) nFiles := ALen( aFiles ) IF nRecips > 100 // "Too many recipients." lRetVal:=FALSE ELSEIF nFiles > 100 // "Too many files." lRetVal:=FALSE ENDIF // Start Mapi IF lRetVal nResult := MAPILogon( 0, NULL_PTR, NULL_PTR, MAPI_LOGON_UI, 0,@nSession ) IF nResult <> SUCCESS lRetVal:=FALSE ENDIF IF lRetVal // Receipients FOR n := 1 UPTO nRecips aRecip[n].ulReserved := 0 aRecip[n].ulRecipClass := MAPI_TO aRecip[n].lpszName := PSZ(_CAST, StringAlloc( aEmail[n] ) ) aRecip[n].lpszAddress := PSZ(_CAST, StringAlloc( aEmail[n] ) ) aRecip[n].ulEIDSize := 0 aRecip[n].lpEntryID := NULL_PTR NEXT // Files FOR n := 1 UPTO nFiles aFile[n].ulReserved :=0 aFile[n].flFlags :=0 aFile[n].nPosition :=0xFFFFFFFF aFile[n].lpszPathName :=PSZ(_CAST, StringAlloc( aFiles[n] ) ) aFile[n].lpszFileName :=NULL_PSZ aFile[n].lpFileType :=NULL_PSZ NEXT sMessage :=MemAlloc( _sizeof( MAPIMessage ) ) sMessage.ulReserved :=0 sMessage.lpszSubject :=PSZ(_CAST, StringAlloc(cSubject)) sMessage.lpszNoteText :=PSZ(_CAST, StringAlloc(cText)) sMessage.lpszMessageType :=NULL_PSZ sMessage.lpszDateReceived :=NULL_PSZ sMessage.lpszConversationID :=NULL_PSZ sMessage.flFlags :=0 sMessage.lpOriginator :=NULL_PTR sMessage.nRecipCount :=nRecips sMessage.lpRecips :=@aRecip sMessage.nFileCount :=nFiles sMessage.lpFiles :=@aFile // Send it lRetVal:=MAPISendMail( nSession, 0, sMessage, MAPI_DIALOG, 0 )=SUCCESS // Clear mem MemFree( sMessage.lpszSubject ) MemFree( sMessage ) FOR n := 1 UPTO nRecips MemFree( aRecip[n].lpszName ) MemFree( aRecip[n].lpszAddress ) NEXT FOR n := 1 UPTO nFiles MemFree( aFile[n].lpszPathName ) NEXT // Logoff MAPILogoff( nSession , 0 , 0 , 0 ) IF lRetVal Warningbox{,"Email","Email is send to cavo@marti.nl!"}:show() ELSE Warningbox{,"Email","Email is not sent!"}:show() ENDIF END END RETURN lRetVal FUNCTION MAPILogon( ulUIParam AS DWORD , ; lpszName AS PSZ , ; lpszPassword AS PSZ , ; flFlags AS DWORD , ; ulReserved AS DWORD , ; lphSession REF DWORD ) AS DWORD PASCAL LOCAL nResult AS DWORD IF _MAPIInit() nResult := DWORD( _CAST , PCALL( sMAPI.pLogon , ; ulUIParam , ; PSZ( _CAST , lpszName ) , ; PSZ( _CAST , lpszPassword ) , ; flFlags , ; 0 , ; @lphSession ) ) ENDIF RETURN nResult FUNCTION MAPILogoff( lhSession AS DWORD , ; ulUIParam AS DWORD , ; flFlags AS DWORD , ; ulReserved AS DWORD ) AS DWORD PASCAL LOCAL nResult AS DWORD IF _MAPIInit() nResult := DWORD( _CAST , PCALL( sMAPI.pLogoff , ; lhSession , ; ulUIParam , ; flFlags , ; ulReserved ) ) ENDIF RETURN nResult FUNCTION MAPISendMail( lhSession AS DWORD , ; ulUIParam AS DWORD , ; lpMessage AS PTR , ; flFlags AS DWORD , ; ulReserved AS DWORD ) AS DWORD PASCAL LOCAL nResult AS DWORD IF _MAPIInit() nResult := DWORD( _CAST , PCALL( sMAPI.pSendMail , lhSession , ; ulUIParam , ; lpMessage , ; flFlags , ; ulReserved ) ) ENDIF RETURN nResult STATIC FUNCTION _MAPIInit() AS LOGIC PASCAL IF hMapi32dll == NULL_PTR hMapi32dll := LoadLibrary( PSZ( _CAST , "MAPI32.DLL" ) ) IF hMapi32dll == NULL_PTR RETURN FALSE ENDIF _RegisterExit( @_MAPIExit() ) sMAPI.pFreeBuffer := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPIFreeBuffer" ) ) sMAPI.pLogoff := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPILogoff" ) ) sMAPI.pLogon := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPILogon" ) ) sMAPI.pDeleteMail := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPIDeleteMail" ) ) sMAPI.pFindNext := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPIFindNext" ) ) sMAPI.pSendMail := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPISendMail" ) ) sMAPI.pReadMail := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPIReadMail" ) ) sMAPI.pResolveName := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPIResolveName" ) ) sMAPI.pSendDocuments := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPISendDocuments" ) ) sMAPI.pSaveMail := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPISaveMail" ) ) sMAPI.pAddress := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPIAddress" ) ) sMAPI.pDetails := GetProcAddress( hMapi32dll , PSZ( _CAST , "MAPIDetails" ) ) ENDIF RETURN TRUE STATIC FUNCTION _MAPIExit() AS VOID PASCAL IF hMapi32dll != NULL_PTR MemSet( @sMAPI , 0 , _sizeof( SimpleMAPIVtbl ) ) FreeLibrary( hMapi32dll ) ENDIF STRUCT MapiMessage ALIGN 4 MEMBER ulReserved AS DWORD MEMBER lpszSubject AS PSZ MEMBER lpszNoteText AS PSZ MEMBER lpszMessageType AS PSZ MEMBER lpszDateReceived AS PSZ MEMBER lpszConversationID AS PSZ MEMBER flFlags AS DWORD MEMBER lpOriginator AS MapiRecipDesc PTR MEMBER nRecipCount AS DWORD MEMBER lpRecips AS MapiRecipDesc PTR MEMBER nFileCount AS DWORD MEMBER lpFiles AS MapiFileDesc PTR STRUCT MapiRecipDesc ALIGN 4 MEMBER ulReserved AS DWORD MEMBER ulRecipClass AS DWORD MEMBER lpszName AS PSZ MEMBER lpszAddress AS PSZ MEMBER ulEIDSize AS DWORD MEMBER lpEntryID AS PTR STRUCT MapiFileDesc ALIGN 4 MEMBER ulReserved AS DWORD MEMBER flFlags AS DWORD MEMBER nPosition AS DWORD MEMBER lpszPathName AS PSZ MEMBER lpszFileName AS PSZ MEMBER lpFileType AS PTR STRUCTURE SimpleMAPIVtbl MEMBER pFreeBuffer AS PTR MEMBER pLogoff AS PTR MEMBER pLogon AS PTR MEMBER pDeleteMail AS PTR MEMBER pFindNext AS PTR MEMBER pSendMail AS PTR MEMBER pReadMail AS PTR MEMBER pResolveName AS PTR MEMBER pSendDocuments AS PTR MEMBER pSaveMail AS PTR MEMBER pAddress AS PTR MEMBER pDetails AS PTR STATIC GLOBAL hMapi32dll AS PTR STATIC GLOBAL sMAPI IS SimpleMAPIVtbl DEFINE MAPI_DIALOG := 0x00000008 DEFINE MAPI_LOGON_UI := 0x00000001 DEFINE MAPI_TO := 1