Need help with MAPI

Just starting out? Need help? Post your questions and find answers here.
TeddyLM
Enthusiast
Enthusiast
Posts: 133
Joined: Wed Apr 30, 2003 2:04 pm
Location: Germany (French expat)

Need help with MAPI

Post 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
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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..
TeddyLM
Enthusiast
Enthusiast
Posts: 133
Joined: Wed Apr 30, 2003 2:04 pm
Location: Germany (French expat)

Post by TeddyLM »

Damn You're right ! It works fine now :)

Merci Fred


(PB .... one giant leap for mankind ) :wink:
TeddyLM
Enthusiast
Enthusiast
Posts: 133
Joined: Wed Apr 30, 2003 2:04 pm
Location: Germany (French expat)

Post 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.
TeddyLM
Enthusiast
Enthusiast
Posts: 133
Joined: Wed Apr 30, 2003 2:04 pm
Location: Germany (French expat)

Post 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
kruddick
User
User
Posts: 11
Joined: Mon Mar 08, 2004 1:15 am

Post 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
TeddyLM
Enthusiast
Enthusiast
Posts: 133
Joined: Wed Apr 30, 2003 2:04 pm
Location: Germany (French expat)

Post by TeddyLM »

Hi kruddick,

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