ref: vbMAPI_Session

On this page you'll find:

Overview

Equivalent MAPI object: IMAPISession
Equivalent Outlook Redemption object: Redemption.RDOSession
Equivalent Outlook Object Model object: Outlook.Namespace
Parent: None.

Class Description

This object is a wrapper for the MAPI IMAPISession object. This is the starting point for logging on to a MAPI profile. To instantiate a new session, use vbMAPI_Init.NewSession to return an object of type vbMAPI_Session.

Use the LogOn method before calling any other methods on this object.

Once logged on, use the Stores method to access the MAPI stores. Use the Accounts method to access the Outlook Account information (requires Outlook 2002 (XP) or newer).

The GetDefaultFolder member is a shortcut to the Stores.DefaultStore.GetDefaultFolder member.


Sub LogOn(Optional ByVal ProfileName As String, _
              Optional ByVal Password As String, _
              Optional ByVal ShowDialog As Boolean, _
              Optional ByVal NewSession As Boolean = True, _
              Optional ByVal ParentWindowHandle As Long, _
              Optional ByVal AllowOthers As Boolean)

Logs on to a MAPI profile.  Often called with no arguments (all are optional).

ProfileName: the name of the MAPI profile to log on to (see Control Panel >> Mail >> Profiles)
ShowDialog: Determines whether MAPI should display a dialog if user input is needed.
NewSession: Whether or not log on to a new or existing MAPI session.
ParentWindowHandle:  parent HWND window handle for dialogs.
AllowOthers: Whether or not to allow other clients to log on to the same MAPI session as the one this creates.

Sub LogOnPSTStore(ByVal FilePath As String, _
              Optional ByVal Format As EnumPSTFileFormat, _
              Optional ByVal DisplayName As String, _
              Optional ByVal Password As String, _
              Optional ByVal Encryption As EnumPSTEncryptionType)

Creates a temporary MAPI profile, adds a PST file to it, and logs you onto that profile so that you can access the PST file directly.

Sub LogOnExchangeMailbox(ByVal User As String, _
              ByVal Server As String, _
              Optional ByVal EncryptConnection As Boolean, _
              Optional ByVal IgnoreNoPF As Boolean)

Creates a temporary MAPI profile, sets up an exchange mailbox on it, and logs you onto that profile so that you can access the mailbox.  You must have the necessary permissions to access the mailbox.

Property Get Stores() As vbMAPI_Stores

Returns a collection of stores available to this MAPI profile.

Property Get Accounts() As vbMAPI_Accounts

Returns a collection of Outlook accounts available to this MAPI profile. (Outlook 2002+).

Property Get Options() As vbMAPI_Options

Returns an object that exposes settings that are global to this session.

Property Get ProfileName() As String

Returns the profile name of the logged on profile.

Function GetDefaultFolder(ByVal DefaultFolder As EnumDefaultFolderType) As vbMAPI_Folder

Returns a specified default folder from the default store.  This is a shortcut to the Session.Stores.DefaultStore.GetDefaultFolder method.

Property Get CurrentUser() As vbMAPI_AddressEntry

Returns the vbMAPI_AddressEntry object representing the currently logged on user.

Sub OutlookSendReceiveAll()

Opens Outlook (if not already open) and forces a send/receive sync.  Sometimes required if the message store is not tightly bound to the exchange server and for POP3/IMAP accounts.  Uses the current session profile if logged on.

Function GetItemFromID(ByVal EntryID As String, _
              Optional ByVal EntryIDStore As String) As vbMAPI_MailItem

Given a valid message EntryID, returns a vbMAPI_MailItem object.  You should also pass the Store EntryID to the second parameter to aid MAPI in locating the object.

Function GetFolderFromID(ByVal EntryID As String, _
              Optional ByVal EntryIDStore As String) As vbMAPI_Folder

Given a valid folder EntryID, returns a vbMAPI_Folder object.  You should also pass the Store EntryID to the second parameter to aid MAPI in locating the object.

Function GetStoreFromID(ByVal EntryID As String, _
              Optional ByVal OpenFlags As EnumOpenStoreFlags = OpenStoreFlags_MAPI_BEST_ACCESS) As vbMAPI_Store

Given a valid store EntryID, returns a vbMAPI_MailStore object.

Function CompareEntryIDs(ByVal EntryID1 As String, _
              ByVal EntryID2 As String) As Boolean

Compares two entry IDs returning True if they represent the same item.  Do not use any other method for comparing EntryIDs - a single item can have multiple valid EntryIDs.

Function GetMessageFromMsgFile(ByVal FilePath As String, _
              Optional ByVal blnCreateNew As Boolean) As vbMAPI_MailItem

Given the path to a MSG or OFT format file, returns a vbMAPI_MailItem object representing the contents of the file.

Property Get Profiles() As vbMAPI_Profiles

Returns a collection of profiles available on this machine.  Does not require the session to be logged on.

Property Get OutlookSignatures() As vbMAPI_OutlookSignatures

Returns a collection of Outlook signatures that have been created on this machine.

Function GetSharedMailbox(ByVal NameOrAddressOrEntryIDOrObject As Variant, _
              Optional ByVal EntryIDFlags As EnumCreateStoreFlags = &Hc, _
              Optional ByVal OpenStoreFlags As EnumOpenStoreFlags = &Hb1) As vbMAPI_Store

Returns a vbMAPI_Store object representing a specific users mailbox.  Pass in the e-mail address, name, or entrid of the user.  Will also accept a vbMAPI_Recipient or vbMAPI_AddressEntry object representing the user.

Function GetSharedDefaultFolder(ByVal NameOrAddressOrEntryIDOrObject As Variant, _
              ByVal DefaultFolder As EnumDefaultFolderType) As vbMAPI_Folder

Returns a specified default folder from the specified mailbox.  This is a shortcut for the GetSharedMailbox().GetDefaultFolder method.

Property Get MAPIOBJECT() As Variant

Property Let MAPIOBJECT(ByVal Value As Variant)

Returns/sets the IMAPISession object associated with this session.

Sub DeliverNow()

Flushes the MAPI spooler queue (only for older versions of Outlook that have an active MAPI spooler).

Property Get AddressBook() As vbMAPI_AddressBook

No information available at this time.


Enumeration description: ExceptionCodesEnum


E_OUT_OF_MEMORY = &H80042210
E_FILE_ERROR = &H8004220c
E_CLOSING_FILE = &H8004220f
E_FILE_NOT_FOUND = &H8004220a
E_ALREADY_LOGGED_ON = &H80042201
E_SESSION_NOT_LOGGED_ON = &H80042202
E_INVALID_STORE = &H80042203
E_INVALID_FOLDER = &H80042204
E_INVALID_MAILITEM = &H80042205
E_INVALID_SESSION = &H80042206
E_INVALID_ACCOUNT = &H80042207
E_UNABLE_TO_OPEN_ADDRESSBOOK = &H80042208
E_FAILED_TO_CREATE_ATTACHMENT = &H80042209
E_OPENING_STREAM = &H8004220b
E_CREATING_FILE = &H8004220d
E_WRITING_FILE = &H8004220e
E_READING_STREAM = &H80042211
E_OPENING_ACCOUNT = &H80042212
E_UNABLE_TO_ACCESS_OUTLOOK_ACCOUNTS = &H80042213
E_OBTAINING_ACCOUNT_INFO = &H80042214
E_ENUMERATING_PROPERTIES = &H80042215
E_UNSUPPORTED = &H80042216
E_WRITING_PROPERTY = &H80042217
E_FAILED_TO_WRAP_OBJECT = &H80042218
E_UNRESOLVABLE_RECIPIENTS = &H80042219
E_OBJECT_MOVED_OR_DELETED = &H8004221a
E_DLL_ERROR = &H8004221b
E_DELETED_RECIPIENT = &H80042220
E_OLK_ACCOUNT_MANAGER = &H80042221
E_INVALID_INDEX = &H80042222
E_INVALID_ADDRESSENTRY = &H80042223
E_INVALID_ENTRYID = &H80042224
E_PROP_NOT_SET = &H80042225
E_INVALID_SIGNATURENAME = &H80042226
E_WRITING_STREAM = &H80042227
E_INVALID_PROFILESERVICE = &H80042228
E_INVALID_PROFILESERVICEPROVIDER = &H80042229
E_INVALID_PROFILESECTION = &H8004222a
E_DELETED_ATTACHMENT = &H8004222b
E_INVALID_ADDRESSLIST = &H8004222c
E_INVALID_ADDRESSBOOK = &H8004222d
E_NO_DEFAULT_PROFILE = &H8004222e
MAPI_E_CALL_FAILED = &H80004005
MAPI_E_NOT_ENOUGH_MEMORY = &H8007000e
MAPI_E_INVALID_PARAMETER = &H80070057
MAPI_E_INTERFACE_NOT_SUPPORTED = &H80004002
MAPI_E_NO_ACCESS = &H80070005
MAPI_E_NO_SUPPORT = &H80040102
MAPI_E_BAD_CHARWIDTH = &H80040103
MAPI_E_STRING_TOO_LONG = &H80040105
MAPI_E_UNKNOWN_FLAGS = &H80040106
MAPI_E_INVALID_ENTRYID = &H80040107
MAPI_E_INVALID_OBJECT = &H80040108
MAPI_E_OBJECT_CHANGED = &H80040109
MAPI_E_OBJECT_DELETED = &H8004010a
MAPI_E_BUSY = &H8004010b
MAPI_E_NOT_ENOUGH_DISK = &H8004010d
MAPI_E_NOT_ENOUGH_RESOURCES = &H8004010e
MAPI_E_NOT_FOUND = &H8004010f
MAPI_E_VERSION = &H80040110
MAPI_E_LOGON_FAILED = &H80040111
MAPI_E_SESSION_LIMIT = &H80040112
MAPI_E_USER_CANCEL = &H80040113
MAPI_E_UNABLE_TO_ABORT = &H80040114
MAPI_E_NETWORK_ERROR = &H80040115
MAPI_E_DISK_ERROR = &H80040116
MAPI_E_TOO_COMPLEX = &H80040117
MAPI_E_BAD_COLUMN = &H80040118
MAPI_E_COMPUTED = &H8004011a
MAPI_E_CORRUPT_DATA = &H8004011b
MAPI_E_UNCONFIGURED = &H8004011c
MAPI_E_FAILONEPROVIDER = &H8004011d
MAPI_E_UNKNOWN_CPID = &H8004011e
MAPI_E_UNKNOWN_LCID = &H8004011f
MAPI_E_PASSWORD_CHANGE_REQUIRED = &H80040120
MAPI_E_PASSWORD_EXPIRED = &H80040121
MAPI_E_INVALID_WORKSTATION_ACCOUNT = &H80040122
MAPI_E_INVALID_ACCESS_TIME = &H80040123
MAPI_E_ACCOUNT_DISABLED = &H80040124
MAPI_E_END_OF_SESSION = &H80040200
MAPI_E_UNKNOWN_ENTRYID = &H80040201
MAPI_E_MISSING_REQUIRED_COLUMN = &H80040202
MAPI_W_NO_SERVICE = &H40203
MAPI_E_BAD_VALUE = &H80040301
MAPI_E_INVALID_TYPE = &H80040302
MAPI_E_TYPE_NO_SUPPORT = &H80040303
MAPI_E_UNEXPECTED_TYPE = &H80040304
MAPI_E_TOO_BIG = &H80040305
MAPI_E_DECLINE_COPY = &H80040306
MAPI_E_UNEXPECTED_ID = &H80040307
MAPI_W_ERRORS_RETURNED = &H40380
MAPI_E_UNABLE_TO_COMPLETE = &H80040400
MAPI_E_TIMEOUT = &H80040401
MAPI_E_TABLE_EMPTY = &H80040402
MAPI_E_TABLE_TOO_BIG = &H80040403
MAPI_E_INVALID_BOOKMARK = &H80040405
MAPI_W_POSITION_CHANGED = &H40481
MAPI_W_APPROX_COUNT = &H40482
MAPI_E_WAIT = &H80040500
MAPI_E_CANCEL = &H80040501
MAPI_E_NOT_ME = &H80040502
MAPI_W_CANCEL_MESSAGE = &H40580
MAPI_E_CORRUPT_STORE = &H80040600
MAPI_E_NOT_IN_QUEUE = &H80040601
MAPI_E_NO_SUPPRESS = &H80040602
MAPI_E_COLLISION = &H80040604
MAPI_E_NOT_INITIALIZED = &H80040605
MAPI_E_NON_STANDARD = &H80040606
MAPI_E_NO_RECIPIENTS = &H80040607
MAPI_E_SUBMITTED = &H80040608
MAPI_E_HAS_FOLDERS = &H80040609
MAPI_E_HAS_MESSAGES = &H8004060a
MAPI_E_FOLDER_CYCLE = &H8004060b
MAPI_W_PARTIAL_COMPLETION = &H40680
MAPI_E_AMBIGUOUS_RECIP = &H80040700
STG_E_INVALIDFUNCTION = &H80030001
STG_E_FILENOTFOUND = &H80030002
STG_E_PATHNOTFOUND = &H80030003
STG_E_TOOMANYOPENFILES = &H80030004
STG_E_ACCESSDENIED = &H80030005
STG_E_INVALIDHANDLE = &H80030006
STG_E_INSUFFICIENTMEMORY = &H80030008
STG_E_INVALIDPOINTER = &H80030009
STG_E_NOMOREFILES = &H80030012
STG_E_DISKISWRITEPROTECTED = &H80030013
STG_E_SEEKERROR = &H80030019
STG_E_WRITEFAULT = &H8003001d
STG_E_READFAULT = &H8003001e
STG_E_SHAREVIOLATION = &H80030020
STG_E_LOCKVIOLATION = &H80030021
STG_E_FILEALREADYEXISTS = &H80030050
STG_E_INVALIDPARAMETER = &H80030057
STG_E_MEDIUMFULL = &H80030070
STG_E_ABNORMALAPIEXIT = &H800300fa
STG_E_INVALIDHEADER = &H800300fb
STG_E_INVALIDNAME = &H800300fc
STG_E_UNKNOWN = &H800300fd
STG_E_UNIMPLEMENTEDFUNCTION = &H800300fe
STG_E_INVALIDFLAG = &H800300ff
STG_E_INUSE = &H80030100
STG_E_NOTCURRENT = &H80030101
STG_E_REVERTED = &H80030102
STG_E_CANTSAVE = &H80030103
STG_E_OLDFORMAT = &H80030104
STG_E_OLDDLL = &H80030105
STG_E_SHAREREQUIRED = &H80030106
STG_E_NOTFILEBASEDSTORAGE = &H80030107
STG_E_EXTANTMARSHALLINGS = &H80030108
STG_E_DOCFILECORRUPT = &H80030109
STG_E_BADBASEADDRESS = &H80030110
STG_E_DOCFILETOOLARGE = &H80030111
STG_E_NOTSIMPLEFORMAT = &H80030112
STG_E_INCOMPLETE = &H80030201
STG_E_TERMINATED = &H80030202
E_UNEXPECTED = &H8000ffff
MAPI_E_EXTENDED_ERROR = &H80040119


Enumeration description: EnumCreateStoreFlags


CreateStoreFlags_USE_ADMIN_PRIVILEGE = &H1
CreateStoreFlags_PUBLIC = &H2
CreateStoreFlags_HOME_LOGON = &H4
CreateStoreFlags_TAKE_OWNERSHIP = &H8
CreateStoreFlags_OVERRIDE_HOME_MDB = &H10
CreateStoreFlags_TRANSPORT = &H20
CreateStoreFlags_REMOTE_TRANSPORT = &H40
CreateStoreFlags_INTERNET_ANONYMOUS = &H80
CreateStoreFlags_ALTERNATE_SERVER = &H100
CreateStoreFlags_IGNORE_HOME_MDB = &H200
CreateStoreFlags_NO_MAIL = &H400
CreateStoreFlags_OVERRIDE_LAST_MODIFIER = &H800
CreateStoreFlags_CALLBACK_LOGON = &H1000
CreateStoreFlags_LOCAL = &H2000
CreateStoreFlags_FAIL_IF_NO_MAILBOX = &H4000
CreateStoreFlags_CACHE_EXCHANGE = &H8000
CreateStoreFlags_CLI_WITH_NAMEDPROP_FIX = &H10000
CreateStoreFlags_ENABLE_LAZY_LOGGING = &H20000
CreateStoreFlags_CLI_WITH_REPLID_GUID_MAPPING_FIX = &H40000
CreateStoreFlags_NO_LOCALIZATION = &H80000
CreateStoreFlags_RESTORE_DATABASE = &H100000
CreateStoreFlags_XFOREST_MOVE = &H0


Enumeration description: EnumOpenStoreFlags


OpenStoreFlags_MAPI_BEST_ACCESS = &H10
OpenStoreFlags_MAPI_DEFERRED_ERRORS = &H8
OpenStoreFlags_MDB_NO_DIALOG = &H1
OpenStoreFlags_MDB_NO_MAIL = &H80
OpenStoreFlags_MDB_ONLINE = &H100
OpenStoreFlags_MDB_TEMPORARY = &H20
OpenStoreFlags_MDB_WRITE = &H0


Enumeration description: EnumPSTFileFormat


PSTFileFormat_Default = &H0
PSTFileFormat_Ansi = &H1
PSTFileFormat_Unicode = &H2


Enumeration description: EnumROHAuthenticateMode


ROHAuthenticate_Basic = &H1
ROHAuthenticate_NTLM = &H2