MAPISessionUtils
Available functions:
function GetExchangeServerName
function GetProfileServiceVersion
function GetMAPISession(const DlgHwnd: UINT_PTR = 0; const ProfileName: String = ''; const LogonFlags: Cardinal = MAPI_USE_DEFAULT; const FromService: Boolean = False; const MultiThreaded: Boolean = False): IMAPISession;
description
Initialize MAPI Subsystem and return IMAPISession Interface
parameters
DlgHwnd - Handle for Logon Dialog. If it is 0 (zero) Logon Dialog will be
Modeless
ProfileName - Profile name. Specify it if you like to open explicit profile
LogonFlags - flags as MAPI_NO_MAIL and etc.. See MSDN documentation
for options
FromService - Is it Windows Service? See MSDN documentation for more
information.
MultiThreaded - Is it MultiThreaded applicaion? See MSDN documentation for more
information.
usage
// Get MAPI Session
MAPISession := GetMAPISession(Self.Handle, '', MAPI_LOGON_UI);
if Assigned(MAPISession) then
StoreList := GetMAPIStores(MAPISession);
procedure ReleaseMapiSession(var MAPISession: IMAPISession);
description
Logoff from MAPI Session and UnInitialize MAPI Subsystem
parameters
MAPISession - IMAPISession, obtained from GetMAPISession function
usage
// Log Off
// Close and clear MAPI Session
ReleaseMapiSession(MAPISession);
function GetProfileName(Const MAPISession: IMAPISession): String;
description
Returns current MAPI Profile Name, as Ourllok
parameters
MAPISession - IMAPISession, obtained from GetMAPISession function
usage
// Get Profile name
StatusBar.Panels[0].Text:='Profile
name: ' + GetProfileName(MAPISession);
function GetProfiles: TStrings;
description
Returns all available MAPI/Outlook profiles. If profile is "default profile", then Object member of TStrings item is equal to 1
parameters
None
usage
// Get Profiles
var
Profiles: TStrings;
iCount: Integer;
TempString: string;
begin
Profiles := GetProfiles;
if not Assigned(Profiles) then
Exit;
for iCount := 0 to Profiles.Count - 1
do
begin
TempString := Profiles.Strings[iCount] + ' - ' + BoolToStr(Boolean(Integer(Profiles.Objects[iCount])),
True);
OutputDebugString(PChar(TempString));
end;
FreeAndNil(Profiles);
end;
function GetExchangeServerName(Const MAPISession: IMAPISession): String;
description
Returns Microsoft Exchange Server Name
parameters
MAPISession - IMAPISession, obtained from GetMAPISession function
usage
ShowMessage(GetExchangeServerName(MAPISession));
function GetAddressBook(Const MAPISession: IMAPISession; UIParam: ULONG_PTR = 0; AllowsDialogs: Boolean = True): IAddrBook;
description
Returns interface to MAPI Address Book
parameters
MAPISession - IMAPISession, obtained from GetMAPISession
function
UIParam - A handle to the parent window of the common address dialog box and
other related displays
AllowsDialogs - if it is False - Suppresses the display of
dialog boxes
usage
// Get Address Book
AddressBook := GetAddressBook(MAPISession, Self.Handle);
// Get recipients
GetRecipientsFromAB(AddressBook, RecipientHeadList, rtBCc, Self.Handle);
procedure GetRecipientsFromAB(const AddressBook: IAddrBook; var Recipients: TRecipientsHeadList; FocussedType: TMAPIRecipientType = rtTo; UIParam: ULONG_PTR = 0; Const DialogTitle: String = 'Select Names');
description
Displays the Outlook address book dialog box and returns an aray of TRecipientHead
parameters
AddressBook- IAddrBook, obtained from GetAddressBook
function
Recipients - An array of TRecipientHead
FocussedType - Indicates the particular text box control that should have the
initial focus when the modal version of the dialog box appears
UIParam - Handle of the parent window of the dialog box
DialogTitle - Text to be used as the title for the common address dialog box
usage
// Get Address Book
AddressBook := GetAddressBook(MAPISession, Self.Handle);
// Show Address Book and get recipients
GetRecipientsFromAB(AddressBook, RecipientHeadList, rtBCc, Self.Handle);
// Set Message Recipients
SetMsgRecipients(MAPIMessage,
AddressBook, RecipientHeadList, Self.Handle);
function GetMAPIStores(const MAPISession: IMAPISession): TStoresHeadList;
description
Returns an array of all available MsgStores
parameters
MAPISession - IMAPISession, obtained from GetMAPISession function
usage
var
StoreList: TStoresHeadList = nil;
...
...
MAPISession := GetMAPISession(Self.Handle, '', MAPI_LOGON_UI);
if Assigned(MAPISession) then
StoreList := GetMAPIStores(MAPISession);
AddStores;
...
...
procedure AddStores;
var
iCount: Integer;
LenA: Integer;
TreeNode: TTreeNode;
begin
LenA := Length(StoreList);
if LenA < 1 then
Exit;
for iCount := 0 to LenA - 1 do
begin
if StoreList[iCount].IsDefault then
TreeNode := MailboxTreeView.Items.AddObjectFirst(nil, StoreList[iCount].DisplayName,
@StoreList[iCount])
else
TreeNode := MailboxTreeView.Items.AddObject(nil, StoreList[iCount].DisplayName,
@StoreList[iCount]);
if StoreList[iCount].IsDefault then
TreeNode.ImageIndex := 0
else
TreeNode.ImageIndex := 1;
TreeNode.SelectedIndex := TreeNode.ImageIndex;
TreeNode.Expanded := False;
end;
end;
function GetDefaultStore(const MAPISession: IMAPISession; const OnLine: Boolean = True; const AllowDialog: Boolean = True; const DialogHandle: UINT_PTR = 0): IMsgStore;
description
Returns default MsgStore for this MAPI Session
parameters
MAPISession - IMAPISession, obtained from GetMAPISession
function
OnLine - if true, forces the live, on-line IMsgStore. Otherwise local, cached
store can be used. applicable only if IMsgStore reside on remote server, as
Microsoft Exchange Server.
AllowDialog - if it is False - Suppresses the display of
dialog boxes, as prompt for message store password
DialogHandle -handle to the parent window of the common address dialog box and
other related displays
usage
fMAPISession := GetMapiSession(Self.Handle, '', MAPI_LOGON_UI);
// Get Profile name
FProfileName := GetProfileName(fMAPISession);
StatusBar.SimpleText := 'Profile name: ' + FProfileName;
// Get Default Store
fMsgStore := GetDefaultStore(fMAPISession);
// Get Calendar folder
fMsgFolder := GetDefaultFolder(fMsgStore, oFolderCalendar);
function GetMAPIStore(const MAPISession: IMAPISession; EntryID: TBytes; const OnLine: Boolean = True; const ReadOnly: Boolean = True; const Temporary: Boolean = False; const AllowDialogs: Boolean = False; const DlgHwnd: UINT_PTR = 0): IMsgStore;
description
Returns specific MsgStore from its entry identifier
parameters
MAPISession - IMAPISession, obtained from GetMAPISession
function
EntryID - unique entry identifier
OnLine - if true, forces the live, on-line IMsgStore. Otherwise local, cached
store can be used. applicable only if IMsgStore reside on remote server, as
Microsoft Exchange Server.
ReadOnly - if True, do not requests read/write permission to the message store
Temporary - Instructs MAPI that the message store is not permanent and should
not be added to the message store table
AllowDialog - if it is False - Suppresses the display of
dialog boxes, as prompt for message store password
DlgHwnd -handle to the parent window of the common address dialog box and other
related displays
usage
var
StoreList: TStoresHeadList = nil;
...
...
MAPISession := GetMAPISession(Self.Handle, '', MAPI_LOGON_UI);
if Assigned(MAPISession) then
StoreList := GetMAPIStores(MAPISession);
...
...
// Get the first Exchange Server Public store
for iCount:=0 to
Length(StoreList) - 1 do
if StoreList[iCount].StoreType = stExchangePublic
then
begin
fMsgStore := GetMAPIStore(MAPISession, StoreList[iCount].ID);
break;
end;
function IsExchangeStore(Const MsgStore: IMsgStore): Boolean;
description
Returns True is MsgStore is an Exchange Server Store, as Mailbox Store, Public Store, Etc..
parameters
MsgStore - IMsgStore interface
usage
// Check for Exchange Store
ListBox.Items.Add('Is Exchange Store: '+ BooltoStr(IsExchangeStore(fMsgStore),
True));
procedure ReleaseMsgStore(MsgStore: IMsgStore);
description
Close and release IMsgStore
parameters
MsgStore - IMsgStore interface
usage
// Check if opened MsgStore is same as the
target MsgStore. if it is a different store, close the current store and open
target store
if not IsSameMAPIObject(MAPISession, MAPIStore,
TargetStoreID) then
begin
ReleaseMsgStore(MAPIStore);
MAPIStore := GetMAPIStore(MAPISession, TargetStoreID);
end;
function IsSameMAPIObject(const MAPISession: IMAPISession; const MAPIProperty: IMAPIProp; EntryID: TBytes): Boolean;
description
Compares entry identifier with opened MAPI property object (IMsgStore, IMAPIFolder, IMessage, etc..) to determine whether it refer to the same object.
parameters
MAPISession - IMAPISession interface
MAPIProperty - an already opened MAPI property object (as IMsgStore,
IMAPIFolder,
etc..) to be compared
EntryID - entry identifier to be compared
usage
// Check if opened MsgStore is same as the
target MsgStore. if it is a different store, close the current store and open
target store
if not IsSameMAPIObject(MAPISession, MAPIStore,
TargetStoreID) then
begin
ReleaseMsgStore(MAPIStore);
MAPIStore := GetMAPIStore(MAPISession, TargetStoreID);
end;
function GetProfileServiceVersion(const ProfileName: string;
var ServerVersion: ULONG; var MajorVersion, MinorVersion, Build, MinorBuild: WORD;
var FoundServerVersion, FoundServerFullVersion: Boolean): Boolean;
overload;
function GetProfileServiceVersion(const MAPISession: IMAPISession;
var ServerVersion: ULONG; </p>MajorVersion, MinorVersion, Build, MinorBuild: WORD;
var FoundServerVersion, FoundServerFullVersion: Boolean): Boolean;
overload;
description
Detect the Version of Exchange Server in an Outlook (2007 and above) Profile
Copyright © 2012 IMIBO Privacy Statement |