LazyMAPI

TMAPISession object represents the Extended MAPI IMAPISession object.
Delphi wrapper object for Extended MAPI IMAPISession interface.

Unit: MAPISession.pas
Type: Class
Inherited from: TObject

Constructors

Name Description
constructor Create(const DlgHwnd: ULONG_PTR = 0) Constructs an instance of the TMAPISession class and initializes its values.
destructor Destroy Destroys the TMAPISession class.

Properties

Name Access Type Description
Active RW Boolean Set MAPI Session to active/closed state. On set True, internally calls method LogOn, on set False, internally calls method LogOff.
MAPIObject RO IMAPISession Returns native MAPI IMAPISession interfaced object.
ProfileName RO WideString Returns the display name of the profile logged on to this session.
MAPIVersion RO WideString Returns the file version of MAPI32.dll
OutlookVersion RO Integer Returns Microsoft Office Outlook installed version as 1997, 1998, 2000, 2002, 2003, 2007, 2010
ForceOnlineStore RW Boolean In Cached Exchange Mode, override the connection to the local message store and open the store on the remote server, when is TRUE.
LogonFlag RO ULONG Bitmask of flags used to control how logon is performed.
WndHandle RO ULONG_PTR Handle to the window to which the MAPI dialog boxes are modal.
DefaultStore RO TMAPIProperty Returns the default for this session message store (TMAPIStore).
Stores RO TMAPIStores Returns TMAPIStores collection - all available message stores for this session.
Inbox RO TMAPIProperty Returns a TMAPIFolder object representing the current users Inbox folder.
Outbox RO TMAPIProperty Returns a TMAPIFolder object representing the current users Outbox folder.
Trashbox RO TMAPIProperty Returns a TMAPIFolder object representing the current users Deleted Items folder.
SentItems RO TMAPIProperty Returns a TMAPIFolder object representing the current users Sent Items folder.

Events

Name Access Type Description
OnBeforeLogOn RW TBeforeLogOnEvent

Occurs immediately before LogOn (MAPILogonEx).

OnBeforeLogOff RW TBeforeLogOffEvent Occurs immediately before LogOff (IMAPISession.LogOff).
OnAfterLogOn RW TAfterLogOnEvent Occurs after LogOn

Methods

Name Description
LogOn The Logon method logs on to the MAPI system.
LogOff The Logoff method logs off from the MAPI system.
CompareIDs The CompareIDs method determines whether two objects are the same object.
   

Top


constructor Create(const DlgHwnd: ULONG_PTR = 0);

description

Constructs an instance of the TMAPISession class and initializes its values.

parameters

DlgHwnd - Handle to the window to which the MAPI dialog boxes are modal.

usage

var FMAPISession:TMAPISession;

 
if not Assigned(FMAPISession) then
begin
  FMAPISession := TMAPISession.Create(Self.Handle);
  FMAPISession.OnBeforeLogOn := BeforeLogOnEvent;
  FMAPISession.OnBeforeLogOff := BeforeLogOffEvent;
  FMAPISession.OnAfterLogOn := AfterLogOnEvent;
end;

FMAPISession.Active := True;
StatusBar.SimpleText := 'MAPIVersion: '+ FMAPISession.MAPIVersion + ' | Outlook version: ' + IntToStr(FMAPISession.OutlookVersion)+ ' | Profile: ' + FMAPISession.ProfileName;

Top


destructor Destroy;

description

Destroys the TMAPISession class.

usage

procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Assigned(FMAPISession) then
  begin
    FMAPISession.Active := False;
    FreeAndNil(FMAPISession);
  end;
end;

Top


TBeforeLogOnEvent = procedure(Sender: TMAPISession; var InitFlags: Cardinal; var LogonFlags: Cardinal) of object;

description

Occurs immediately before LogOn (MAPILogonEx).

parameters

InitFlags - Flags used for initializing MAPI Subsystem. Default value is 0 (zero). Valid flags are: MAPI_MULTITHREAD_NOTIFICATIONS, MAPI_NT_SERVICE, MAPI_NO_COINIT;

LogonFlags - Bitmask of flags used to control how logon is performed. Default value is (MAPI_ALLOW_OTHERS or MAPI_USE_DEFAULT or MAPI_EXTENDED). Valid flags are: MAPI_ALLOW_OTHERS, MAPI_BG_SESSION, MAPI_EXPLICIT_PROFILE, MAPI_EXTENDED, MAPI_FORCE_DOWNLOAD, MAPI_LOGON_UI, MAPI_NEW_SESSION, MAPI_NO_MAIL, MAPI_NT_SERVICE, MAPI_SERVICE_UI_ALWAYS, MAPI_TIMEOUT_SHORT, MAPI_UNICODE, MAPI_USE_DEFAULT.
For explanation of these flags please see MSDN (Microsoft Developer Network) library.

usage

procedure TfrmMain.BeforeLogOnEvent(Sender: TMAPISession; var InitFlags: Cardinal; var LogonFlags: Cardinal);
begin
  // nothing
end;

Top


TBeforeLogOffEvent = procedure(Sender: TMAPISession; var CloseWndHandle: ULONG_PTR; var LogOffFlags: Cardinal) of object;

description

Occurs immediately before LogOn (MAPILogonEx).

parameters

CloseWndHandle - A handle to the parent window of any dialog boxes or windows to be displayed.

LogOffFlags - A bitmask of flags that control the logoff operation. Default value is 0 (zero). The following flags can be set: MAPI_LOGOFF_SHARED, MAPI_LOGOFF_UI.      

usage

procedure TfrmMain.BeforeLogOffEvent(Sender: TMAPISession; var CloseWndHandle: ULONG_PTR; var LogOffFlags: Cardinal);
begin
  // nothing
end;

Top


TAfterLogOnEvent = procedure(Sender: TMAPISession) of object;

description

Occurs immediately after LogOn.

usage

procedure TfrmMain.AfterLogOnEvent(Sender: TMAPISession);
begin
  // nothing
end;

Top


procedure LogOn(const ProfileName: WideString = ''; const AllowsDialogs: Boolean = True; const NewSession: Boolean = True; const NoMail: Boolean = True;
const AsService: Boolean = False; const ProfileInfo: AnsiString = '');

description

Logs on to the MAPI system. Internally calls Extended MAPI RAW functions MAPIInitialize and MAPILogonEx.

parameters

ProfileName - String that contains the name of the profile to use when the user logs on. This string is limited to 64 characters. Empty string means default profile.
AllowsDialogs - A dialog box should be displayed to prompt the user for logon information if required.
NewSession - An attempt should be made to create a new MAPI session instead of acquiring the shared session. If the NewSession flag isFalse, LogOn uses an existing shared session even if the ProfileName parameter is not empty string.
NoMail - MAPI should not inform the MAPI spooler of the session's existence. The result is that no messages can be sent or received in the session except through a tightly coupled store and transport pair.
AsService - The Application is running as a Windows service. Applications that are not running as a Windows service should not set this flag to True; Applications that are running as a service must set this flag to True.
ProfileInfo - Instructs TMAPISession to create and use a temporary profile. Contains the server and mailbox names that LogOn should use to create a new profile for this session, delimited by CRLF, i.e.  ProfileInfo:='MyExchangeServer'#13#10'MyOwnMailbox' . The profile is deleted after logon is completed or terminated. Microsoft Exchange Server specific. 

usage

if not FMAPISession.Active then
  FMAPISession.LogOn('Second Account'); // Log on to profile named "Second Accound"

Top


procedure LogOff;

description

The Logoff method logs off from the MAPI system.

usage

procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 if Assigned(FMAPISession) then
   begin
     // Close and clear MAPI Session
     FMAPISession.LogOff; // or FMAPISession.Active := False;
     FreeAndNil(FMAPISession);
  end;
end;

Top


function CompareIDs(const ID1, ID2: TBytes): Boolean;

description

Determines whether two objects are the same object.

parameters

ID1 - The unique identifier of the first object to be compared.
ID2 - The unique identifier of the second object to be compared.

usage

function IsSameFolder(const MAPISession:TMAPISession; const Folder1, Folder2:TMAPIFolder):Boolean;
begin
 Result:= MAPISession.CompareIDs(Folder1.ID, Folder2.ID);
end;

Top


Copyright © 2012 IMIBO
Privacy Statement