See the unit below (BaclMsOutlookHelper.pas). It will detect/retreive
settings from various flavors of Outlook (2000, '98, Express, etc.) and
released under MPL 1.1. Also part of my code lib "BACL", I have units for
Netscape flavors, Opera, Eudora, etc. If you need them, please feel free to
contact me about them.
Sorry if this posted twice - I was having some technical difficulty :)
Hope that helps,
Bryan Ashby
bas...@NOSPAM.FOR.ME.THANK.YOU.iaccess.com
--[snip]--
{***************************************************************************
***}
{
}
{ Bryan Ashby's Code Library
}
{ MS Outlook
}
{
}
{ Author...............Bryan Ashby
}
{ Original
pas }
{
}
{ Last
}
{
}
{ The contents of this file are subject to the Mozilla
}
{ License Version 1.1 (the "License"); you may not use this
}
{ except in compliance with the License. You may obtain a copy
}
{ the License at
}
{
}
{ Software distributed under the License is distributed on an
}
{ IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
}
{ implied. See the License for the specific language
}
{ rights and limitations under the
}
{
}
{ The Original Code is Bryan Ashby's Code Library
}
{
}
{ The Initial Developer of the Original Code is Bryan Ashby. Portions
created }
{ by Bryan Ashby are Copyright (C) 2000, 2001 Bryan Ashby. All
}
{
}
{
}
{
}
{
}
{ Revision
}
{ 2001-02-09: Now using OUTLOOK_SMTP_DISPLAY_NAME instead
}
{ OUTLOOK_ACCOUNT_NAME when detecting installed Outlook version -
is }
{ should be much more
}
{ 2001-02-14: Added GetMsOutlookDefaultAccount
}
{ 2001-Mar-30: Renamed GetMsOutlookDefaultAccount
}
{ GetMsOutlookDefaultAccountStr which returns a nnnnnnnn string
ue }
{ and added GetMsOutlookDefaultAccountId which returns a DWORD
ud. }
{ The following functions now use RegOpenKeyEx instead
}
{ RegCreateKeyEx: GetMsOutlookDefaultAccountStr,
GetDetectedOutlookType, }
{ and
}
{ Removed end backslash \ from
XPRESS. }
{ Now properly setting DataSize before each call to RegQueryValueEx
}
{
}
{ 2001-Apr-06: Removed GetMsOutlookDefaultAccountId function
}
{ discovering that some versions of Outlook do not store account IDs
in }
{ a numerical format. GetMsOutlookAccountEntryInfo now expects
}
{ AccountId to be a string, ie 00000001 or
}
{ 2001-Apr-09: Fixed bug in GetMsOutlookDefaultAccountStr that
}
{ causing account 00000001 to always be detected as the default
account. }
{
}
{***************************************************************************
***}
unit BaclMsOutlookHelper;
interface
uses
Windows,
SysUtils;
const
//
// Ms Outlook Account Registry Bases
//
OUTLOOK_ACCOUNT_2000 =
'Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts';
OUTLOOK_ACCOUNT_98 =
'Software\Microsoft\Office\8.0\Outlook\OMI Account Manager\Accounts';
OUTLOOK_ACCOUNT_EXPRESS =
'Software\Microsoft\Internet Account Manager\Accounts';
//
// Ms Outlook Account Entry Registry Names
//
OUTLOOK_ACCOUNT_NAME = 'Account Name';
OUTLOOK_POP3_SERVER = 'POP3 Server';
OUTLOOK_POP3_USER_NAME = 'POP3 User Name';
OUTLOOK_SMTP_DISPLAY_NAME = 'SMTP Display Name';
OUTLOOK_SMTP_EMAIL_ADDRESS = 'SMTP Email Address';
OUTLOOK_SMTP_SERVER = 'SMTP Server';
type
//
// Supported Outlook Installation Types
//
TOutlookTypes = (otNone, ot98, ot2000, otExpress);
function GetMsOutlookDefaultAccountStr (const OutlookType : TOutlookTypes) :
string;
{function GetMsOutlookDefaultAccountId (const OutlookType : TOutlookTypes) :
DWORD; }
{function GetMsOutlookAccountEntryInfo (const OutlookType : TOutlookTypes;
const AccountId : DWORD; const EntryId : string) : string; }
function GetMsOutlookAccountEntryInfo (const OutlookType : TOutlookTypes;
const AccountId : string; const EntryId : string) : string;
function GetDetectedOutlookType : TOutlookTypes;
implementation
//--------------------------------------------------------------------------
----
function GetMsOutlookDefaultAccountStr (const OutlookType : TOutlookTypes) :
string;
const
OUTLOOK_ACCOUNT_DEF_MAIL = 'Default Mail Account';
//
// These are simular to the global constants found above, except
// for the trailing \Accounts part - Account Manager is as far as we
// want to go here.
//
OUTLOOK_ACCOUNT_2000 =
'Software\Microsoft\Office\Outlook\OMI Account Manager';
OUTLOOK_ACCOUNT_98 =
'Software\Microsoft\Office\8.0\Outlook\OMI Account Manager';
OUTLOOK_ACCOUNT_EXPRESS =
'Software\Microsoft\Internet Account Manager';
var
OpenKey : HKEY;
SubKey : string;
DataType,
DataSize : DWORD;
Temp : array [0..2048] of char;
begin
//
// Default to the first account
//
Result := '00000001';
case OutlookType of
otNone : Exit;
ot98 : SubKey := OUTLOOK_ACCOUNT_98;
ot2000 : SubKey := OUTLOOK_ACCOUNT_2000;
otExpress : SubKey := OUTLOOK_ACCOUNT_EXPRESS;
end;
if RegOpenKeyEx (HKEY_CURRENT_USER, PChar(SubKey),
REG_OPTION_NON_VOLATILE,
KEY_READ, OpenKey) = ERROR_SUCCESS then
begin
DataType := REG_SZ;
DataSize := SizeOf(Temp);
if RegQueryValueEx (OpenKey, OUTLOOK_ACCOUNT_DEF_MAIL, nil, @DataType,
@Temp, @DataSize) = ERROR_SUCCESS then
Result := string(Temp);
RegCloseKey (OpenKey);
end;
end;
//--------------------------------------------------------------------------
----
(*
function GetMsOutlookDefaultAccountId (const OutlookType : TOutlookTypes) :
DWORD;
const
OUTLOOK_ACCOUNT_DEF_MAIL = 'Default Mail Account';
var
OpenKey : HKEY;
SubKey : string;
DataType,
DataSize : DWORD;
Buffer : array [0..2048] of char;
Temp : string;
begin
//
// Default to first account
//
Result := 1;
case OutlookType of
otNone : Exit;
ot98 : SubKey := OUTLOOK_ACCOUNT_98;
ot2000 : SubKey := OUTLOOK_ACCOUNT_2000;
otExpress : SubKey := OUTLOOK_ACCOUNT_EXPRESS;
end;
if RegOpenKeyEx (HKEY_CURRENT_USER, PChar(SubKey),
REG_OPTION_NON_VOLATILE,
KEY_READ, OpenKey) = ERROR_SUCCESS then
begin
DataType := REG_SZ;
DataSize := SizeOf(Buffer);
if RegQueryValueEx (OpenKey, OUTLOOK_ACCOUNT_DEF_MAIL, nil, @DataType,
@Buffer, @DataSize) = ERROR_SUCCESS then
begin
Temp := string(Buffer);
Result := StrToIntDef (Temp,1);
end;
RegCloseKey (OpenKey);
end;
end;
*)
//--------------------------------------------------------------------------
----
(*
function GetMsOutlookAccountEntryInfo (const OutlookType : TOutlookTypes;
const AccountId : DWORD; const EntryId : string) : string;
var
OpenKey : HKEY;
Temp : array [0..2048] of char;
DataSize,
DataType : Integer;
SubKey : string;
begin
//
// Check for errornous AccountId
//
if AccountId <= 0 then
Exit;
//
// Determin Sub Key to open
//
case OutlookType of
otNone : Exit;
ot98 : SubKey := OUTLOOK_ACCOUNT_98;
ot2000 : SubKey := OUTLOOK_ACCOUNT_2000;
otExpress : SubKey := OUTLOOK_ACCOUNT_EXPRESS;
end;
SubKey := SubKey + '\' + Format ('%.8d', [AccountId]);
if RegOpenKeyEx (HKEY_CURRENT_USER, PChar(SubKey),
REG_OPTION_NON_VOLATILE,
KEY_READ, OpenKey) = ERROR_SUCCESS then
begin
DataType := REG_SZ;
DataSize := SizeOf(Temp);
if RegQueryValueEx (OpenKey, PChar(EntryId), nil, @DataType, @Temp,
@DataSize) = ERROR_SUCCESS then
Result := string(Temp)
else
Result := '';
RegCloseKey (OpenKey);
end;
end;
*)
//--------------------------------------------------------------------------
----
function GetMsOutlookAccountEntryInfo (const OutlookType : TOutlookTypes;
const AccountId : string; const EntryId : string) : string;
var
OpenKey : HKEY;
Temp : array [0..2048] of char;
DataSize,
DataType : Integer;
SubKey : string;
begin
//
// Check for errornous AccountId
//
if Length(AccountId) < 8 then
Exit;
//
// Determin Sub Key to open
//
case OutlookType of
otNone : Exit;
ot98 : SubKey := OUTLOOK_ACCOUNT_98;
ot2000 : SubKey := OUTLOOK_ACCOUNT_2000;
otExpress : SubKey := OUTLOOK_ACCOUNT_EXPRESS;
end;
SubKey := SubKey + '\' + AccountId;
if RegOpenKeyEx (HKEY_CURRENT_USER, PChar(SubKey),
REG_OPTION_NON_VOLATILE,
KEY_READ, OpenKey) = ERROR_SUCCESS then
begin
DataType := REG_SZ;
DataSize := SizeOf(Temp);
if RegQueryValueEx (OpenKey, PChar(EntryId), nil, @DataType, @Temp,
@DataSize) = ERROR_SUCCESS then
Result := string(Temp)
else
Result := '';
RegCloseKey (OpenKey);
end;
end;
//--------------------------------------------------------------------------
----
function GetDetectedOutlookType : TOutlookTypes;
const
OUTLOOK_FIRST_ACCOUNT = '00000001';
var
OpenKey : HKEY;
DataSize,
DataType : Integer;
Temp : array [0..2048] of char;
begin
Result := otNone;
DataType := REG_SZ;
//
// Outlook Express
//
if RegOpenKeyEx (HKEY_CURRENT_USER, OUTLOOK_ACCOUNT_EXPRESS + '\' +
OUTLOOK_FIRST_ACCOUNT, REG_OPTION_NON_VOLATILE, KEY_READ, OpenKey) =
ERROR_SUCCESS then
begin
DataSize := SizeOf(Temp);
if RegQueryValueEx (OpenKey, OUTLOOK_SMTP_DISPLAY_NAME, nil, @DataType,
@Temp, @DataSize) = ERROR_SUCCESS then
if not (string(Temp) = '') then
Result := otExpress;
RegCloseKey (OpenKey);
end;
FillChar (Temp, SizeOf(Temp), #0);
//
// Outlook 98
//
if
...
read more »