Need help with MAPI
Posted: Mon Apr 05, 2004 11:35 am
Hi there,
i'd like to program an Email-Checker for my MAPI-Client Account at the office. I know my ProfileName is correct and no Password is required but i get a 'MAPI_E_FAILURE' when i try to Logon. I'm no API-Guru and i probably did something wrong... Can somebody tell me where the problem is ? Thanks in advance.
Here is my code :
;MAPILogon Test (Messaging Application Programming Interface)
;*************************
;**** CONSTANTS LOGON ****
;*************************
#Library = 1
#MAPI_LOGON_UI = $1
#MAPI_NEW_SESSION = $2
#MAPI_ALLOW_OTHERS = $8
#MAPI_EXPLICIT_PROFILE = $10
#MAPI_EXTENDED = $20
#MAPI_USE_DEFAULT = $40
#MAPI_FORCE_DOWNLOAD = $1000
#MAPI_SERVICE_UI_ALWAYS = $2000
#MAPI_NO_MAIL = $8000
#MAPI_PASSWORD_UI = $20000
#MAPI_TIMEOUT_SHORT = $100000
#MAPI_UNICODE = $80000000
;*************************
#MAPI_E_FAILURE = 2
#MAPI_E_INSUFFICIENT_MEMORY = 5
#MAPI_E_LOGIN_FAILURE = 3
#MAPI_E_TOO_MANY_SESSIONS = 8
#MAPI_E_USER_ABORT = 1
#SUCCESS_SUCCESS = 0
MAPILogonProfileName$ = "MS Exchange-Einstellungen"
MAPILogonPassword$ = ""
MAPIHandleSession.l = 0
;****************************
;******* INIT LIBRARY *******
;****************************
If OpenLibrary(#Library, "MAPI32.DLL")
lptMAPIFunctionLogon = IsFunction(#Library, "MAPILogon")
lptMAPIFunctionLogoff = IsFunction(#Library, "MAPILogoff")
Else
Debug "ERROR : couldn't find MAPI32.DLL" : End
EndIf
;**************************
;******* MAPI LOGON *******
;**************************
;Source MSDN (Simple MAPI) :
;ULONG FAR PASCAL MAPILogon(
; ULONG ulUIParam, --> Parent window handle or zero
; LPTSTR lpszProfileName, --> Pointer to a null-terminated profile name string (<=256 char)
; LPTSTR lpszPassword, --> Pointer to a null-terminated credential string (<=256 char)
; FLAGS flFlags, --> Bitmask of option flags
; ULONG ulReserved, --> Reserved, must be zero
; LPLHANDLE lplhSession --> (out) simple MAPI session handle

Debug "Trying to open a MAPI session :"
;TRY TO OPEN A NEW SESSION
Result.l = CallFunctionFast(lptMAPIFunctionLogon, 0, @MAPILogonProfileName$, @MAPILogonPassword$, #MAPI_NEW_SESSION, 0, MAPIHandleSession)
If Result<>#SUCCESS_SUCCESS
;OR TO ACQUIRE A SHARED ONE
Result.l = CallFunctionFast(lptMAPIFunctionLogon, 0, 0, 0, 0, 0, MAPIHandleSession)
If Result<>#SUCCESS_SUCCESS
Debug "+ERROR Nr." + Str(Result) + " (unable to obtain a MAPI session)"
CloseLibrary(#Library)
End
EndIf
EndIf
Debug "OK session opened : " + Str(MAPIHandleSession)
;***************************
;******* MAPI LOGOFF *******
;***************************
Debug "Closing MAPI session"
Result = CallFunctionFast(lptMAPIFunctionLogoff, MAPIHandleSession,0,0,0)
If Result<>0
Debug "+ERROR Nr." + Str(Result) + " : (unable to close session)"
End
EndIf
Debug "OK session closed"
;*****************************
;******* CLOSE LIBRARY *******
;*****************************
CloseLibrary(#Library)
End
i'd like to program an Email-Checker for my MAPI-Client Account at the office. I know my ProfileName is correct and no Password is required but i get a 'MAPI_E_FAILURE' when i try to Logon. I'm no API-Guru and i probably did something wrong... Can somebody tell me where the problem is ? Thanks in advance.
Here is my code :
;MAPILogon Test (Messaging Application Programming Interface)
;*************************
;**** CONSTANTS LOGON ****
;*************************
#Library = 1
#MAPI_LOGON_UI = $1
#MAPI_NEW_SESSION = $2
#MAPI_ALLOW_OTHERS = $8
#MAPI_EXPLICIT_PROFILE = $10
#MAPI_EXTENDED = $20
#MAPI_USE_DEFAULT = $40
#MAPI_FORCE_DOWNLOAD = $1000
#MAPI_SERVICE_UI_ALWAYS = $2000
#MAPI_NO_MAIL = $8000
#MAPI_PASSWORD_UI = $20000
#MAPI_TIMEOUT_SHORT = $100000
#MAPI_UNICODE = $80000000
;*************************
#MAPI_E_FAILURE = 2
#MAPI_E_INSUFFICIENT_MEMORY = 5
#MAPI_E_LOGIN_FAILURE = 3
#MAPI_E_TOO_MANY_SESSIONS = 8
#MAPI_E_USER_ABORT = 1
#SUCCESS_SUCCESS = 0
MAPILogonProfileName$ = "MS Exchange-Einstellungen"
MAPILogonPassword$ = ""
MAPIHandleSession.l = 0
;****************************
;******* INIT LIBRARY *******
;****************************
If OpenLibrary(#Library, "MAPI32.DLL")
lptMAPIFunctionLogon = IsFunction(#Library, "MAPILogon")
lptMAPIFunctionLogoff = IsFunction(#Library, "MAPILogoff")
Else
Debug "ERROR : couldn't find MAPI32.DLL" : End
EndIf
;**************************
;******* MAPI LOGON *******
;**************************
;Source MSDN (Simple MAPI) :
;ULONG FAR PASCAL MAPILogon(
; ULONG ulUIParam, --> Parent window handle or zero
; LPTSTR lpszProfileName, --> Pointer to a null-terminated profile name string (<=256 char)
; LPTSTR lpszPassword, --> Pointer to a null-terminated credential string (<=256 char)
; FLAGS flFlags, --> Bitmask of option flags
; ULONG ulReserved, --> Reserved, must be zero
; LPLHANDLE lplhSession --> (out) simple MAPI session handle

Debug "Trying to open a MAPI session :"
;TRY TO OPEN A NEW SESSION
Result.l = CallFunctionFast(lptMAPIFunctionLogon, 0, @MAPILogonProfileName$, @MAPILogonPassword$, #MAPI_NEW_SESSION, 0, MAPIHandleSession)
If Result<>#SUCCESS_SUCCESS
;OR TO ACQUIRE A SHARED ONE
Result.l = CallFunctionFast(lptMAPIFunctionLogon, 0, 0, 0, 0, 0, MAPIHandleSession)
If Result<>#SUCCESS_SUCCESS
Debug "+ERROR Nr." + Str(Result) + " (unable to obtain a MAPI session)"
CloseLibrary(#Library)
End
EndIf
EndIf
Debug "OK session opened : " + Str(MAPIHandleSession)
;***************************
;******* MAPI LOGOFF *******
;***************************
Debug "Closing MAPI session"
Result = CallFunctionFast(lptMAPIFunctionLogoff, MAPIHandleSession,0,0,0)
If Result<>0
Debug "+ERROR Nr." + Str(Result) + " : (unable to close session)"
End
EndIf
Debug "OK session closed"
;*****************************
;******* CLOSE LIBRARY *******
;*****************************
CloseLibrary(#Library)
End