Page 1 of 1

Need help with MAPI

Posted: Mon Apr 05, 2004 11:35 am
by TeddyLM
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

Posted: Mon Apr 05, 2004 12:01 pm
by Fred
You will need to use an address for the handle return:

Result.l = CallFunctionFast(lptMAPIFunctionLogon, 0, @MAPILogonProfileName$, @MAPILogonPassword$, #MAPI_NEW_SESSION, 0, @MAPIHandleSession)

I hope this helps..

Posted: Mon Apr 05, 2004 2:36 pm
by TeddyLM
Damn You're right ! It works fine now :)

Merci Fred


(PB .... one giant leap for mankind ) :wink:

Posted: Wed Apr 07, 2004 6:58 am
by TeddyLM
My Project looks fine so far, but i have another problem.

How can i 'switch off' the Outlook security warning message wenn i use the functions : MAPIReadMail, MAPIResolveName and MAPISendMail ?

I found a few Registry hacks on the Net but nothing worked (W2k / Office 2000).

Thanks for the help.

Posted: Wed Apr 07, 2004 12:38 pm
by TeddyLM
Don't know how to desactivate this f... Popup window.
I tried another way ... i added a thread to check if the window pops up and send keys (Right & Return) to press the Yes button. The window only appears 0,2 sec.

If somebody has a better idea... please tell me !

Thanks

Posted: Wed Apr 07, 2004 1:32 pm
by kruddick
Hmm...

Sounds like you are using Outlook 2000/2002 and having problems with the security features... you may need to look here for ideas:

http://www.dimastr.com/redemption/

or

http://www.outlookcode.com/d/mapi.htm

in the tools section for a tool that gets around it.

Kent

Posted: Wed Apr 07, 2004 10:39 pm
by TeddyLM
Hi kruddick,

Thank you for the links. I'll have a look at that tomorrow.
Good night (23:41 in Germany)