Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem getting MAPI session object
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Problem getting MAPI session object
Miscellaneous
Thread ID:
00970819
Message ID:
00970819
Views:
83
Some of my users report that they are not able to send e-mail using Outlook Express (MAPI). Does anybody see some obvious problems with the following code?

cmapi.openmapisession():

**************************************************
* Creates a session from UserName and Password
*
* Populates object reference and returns session id
*
**************************************************

LPARAMETERS lcUserName, lcPassword, llDownloadMail

LOCAL lnHandle, lnProfiles, lnDataSize, lcDefaultProfile

DECLARE INTEGER RegOpenKeyEx IN Win32API ;
INTEGER nStartHandle, ;
STRING cKeyToOpen, ;
INTEGER nReservedZero, ;
INTEGER nSecurityAccess, ;
INTEGER @nOpenHandle

DECLARE INTEGER RegQueryValueEx IN Win32API ;
INTEGER nOpenHandle, ;
STRING cValueToQuery, ;
INTEGER nReservedZero, ;
INTEGER nValueType, ;
STRING @cDataBuffer, ;
INTEGER @nSizeOfData

DECLARE INTEGER RegQueryInfoKey IN Win32API ;
INTEGER nOpenHandle, ;
STRING cClassString, ;
INTEGER nSizeOfClassString, ;
INTEGER nReservedNull, ;
INTEGER @nSubKeys, ;
INTEGER nLongestSubKey, ;
INTEGER nLongestClass, ;
INTEGER nValues, ;
INTEGER nLongestValueName, ;
INTEGER nLongestValueData, ;
INTEGER nSecurityDescriptor, ;
INTEGER nLastWriteTime

STORE 0 TO lnHandle, lnProfiles
STORE 254 TO lnDataSize
STORE SPACE(lnDataSize) TO lcDefaultProfile
*- Open the MAPI Profiles key
RegOpenKeyEx(-2147483647, "Software\Microsoft\Windows Messaging Subsystem\Profiles", 0, 0, @lnHandle)
*- Find out how many profiles exist
RegQueryInfoKey(lnHandle, "", 0, 0, @lnProfiles, 0, 0, 0, 0, 0, 0, 0)

IF lnProfiles>1
*- Identify the default profile
RegQueryValueEx(lnHandle, "DefaultProfile", 0, 0, @lcDefaultProfile, @lnDataSize)
ENDIF

lSessionError = .f.
lcOldError = ON("ERROR")
ON ERROR lSessionError = .T.
lcOldFolder=SYS(5)+SYS(2003)
IF TYPE("THIS.oSession")='O'
IF THIS.oSession.UserName=lcUserName ;
AND THIS.oSession.Password=lcPassword
RETURN THIS.oSession.SessionID
ELSE
THIS.oSession.SignOff()
ENDIF
ENDIF
THIS.oSession=CREATEOBJECT("MSMAPI.MAPISession.1")
IF lnProfiles>1
*- Create new session if multi-profile
This.oSession.NewSession=.T.
ENDIF
IF ! EMPTY(lcUserName)
THIS.oSession.UserName=lcUserName
ENDIF
IF lnProfiles>1 AND EMPTY(lcUserName)
*- Use default profile if no profile specified
This.oSession.UserName=lcDefaultProfile
ENDIF
THIS.oSession.Password=lcPassword
THIS.oSession.DownloadMail=llDownloadMail
THIS.oSession.SignOn()
SET DEFAULT TO (lcOldFolder)
ON ERROR &lcOlderror

RETURN ! lSessionError AND THIS.oSession.SessionID <> 0
Vidar Johannessen
Next
Reply
Map
View

Click here to load this message in the networking platform