Test Microsoft Office Outlook Account Management
 
unit uMain;
 
 
interface
 
 
{$I IMI.INC}
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ExtendedMAPI, ComCtrls, Spin;
 
type
  TFrmAccounts = class(TForm)
    Panel1: TPanel;
    btLogOn: TButton;
    cbAccounts: TComboBox;
    Label1: TLabel;
    StatusBar: TStatusBar;
    PageControl1: TPageControl;
    tsEmailSetings: TTabSheet;
    btDisplayAccounts: TButton;
    btNewAccount: TButton;
    Label2: TLabel;
    Label3: TLabel;
    ebUserName: TEdit;
    Label4: TLabel;
    ebUserEmailAddress: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    cbAccountType: TComboBox;
    Label7: TLabel;
    ebIncomingServer: TEdit;
    Label8: TLabel;
    ebOutgoingServer: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    ebLogonUserName: TEdit;
    cbSPA: TCheckBox;
    tsGeneral: TTabSheet;
    GroupBox1: TGroupBox;
    Label13: TLabel;
    ebReplayEmail: TEdit;
    Label12: TLabel;
    ebOrganization: TEdit;
    Label11: TLabel;
    ebMailAccount: TEdit;
    GroupBox2: TGroupBox;
    cbSMTPReqAuth: TCheckBox;
    rbUseSameSettings: TRadioButton;
    rbSMTPLogOnUsing: TRadioButton;
    Label14: TLabel;
    ebUserNameSMTP: TEdit;
    cbRememberSMTPPassword: TCheckBox;
    cbOutgoingSPA: TCheckBox;
    rbLogonBefore: TRadioButton;
    GroupBox3: TGroupBox;
    Label16: TLabel;
    ebPOP3Port: TEdit;
    Label17: TLabel;
    ebSMTPPort: TEdit;
    cbIncomingSSL: TCheckBox;
    Label18: TLabel;
    cbEncrType: TComboBox;
    Label19: TLabel;
    ebServerTimeOuts: TEdit;
    GroupBox4: TGroupBox;
    cbLeaveCopy: TCheckBox;
    cbRemoveFromServer: TCheckBox;
    seDays: TSpinEdit;
    Label20: TLabel;
    cbRemoveDeleted: TCheckBox;
    Label21: TLabel;
    procedure btLogOnClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btDisplayAccountsClick(Sender: TObject);
    procedure btNewAccountClick(Sender: TObject);
    procedure cbAccountsChange(Sender: TObject);
  private
    { Private declarations }
    MAPISession: IMAPISession;
    procedure GetAccountManager;
  public
    { Public declarations }
  end;
 
 
var
  FrmAccounts: TFrmAccounts;
 
 
implementation
 
 
uses MAPISessionUtils, MAPIAccountManager;
 
{$R *.dfm}
 
 
var
  oMAPIAccountManager: TMAPIAccountManager = nil;
 
 
const
  strLogOff: array [Boolean] of string = ('Log On', 'Log Off');
 
 
procedure TFrmAccounts.GetAccountManager;
var
  iCount, cCount: Integer;
begin
  oMAPIAccountManager := TMAPIAccountManager.Create(MAPISession);
  cCount := oMAPIAccountManager.Count;
  StatusBar.SimpleText := ' Accounts count: ' + IntToStr(cCount);
  if cCount < 1 then
    Exit;
 
  for iCount := 0 to cCount - 1 do
    cbAccounts.Items.Add(oMAPIAccountManager.Account[iCount].AccountName);
 
  btDisplayAccounts.Enabled := True;
  btNewAccount.Enabled := True;
end;
 
 
procedure TFrmAccounts.btDisplayAccountsClick(Sender: TObject);
begin
  oMAPIAccountManager.DisplayAccountList(Self.Handle);
end;
 
 
procedure TFrmAccounts.btLogOnClick(Sender: TObject);
begin
  if btLogOn.Tag = 0 then
  // Log On
  begin
    // Get MAPI Session
    MAPISession := GetMAPISession(Self.Handle, '', MAPI_LOGON_UI);
    if Assigned(MAPISession) then
      GetAccountManager;
  end
  else
  // Log Off
  begin
    btDisplayAccounts.Enabled := False;
    btNewAccount.Enabled := False;
 
    cbAccounts.Items.Clear;
    if Assigned(oMAPIAccountManager) then
      FreeAndNil(oMAPIAccountManager);
    // Close and clear MAPI Session
    ReleaseMapiSession(MAPISession);
  end;
  btLogOn.Tag := Integer(Assigned(MAPISession));
  btLogOn.Caption := strLogOff[Bool(btLogOn.Tag)];
end;
 
 
procedure TFrmAccounts.btNewAccountClick(Sender: TObject);
begin
  oMAPIAccountManager.DisplayAddNewAccountWizard(Self.Handle);
end;
 
 
procedure TFrmAccounts.cbAccountsChange(Sender: TObject);
var
  ProfileAccount: TMAPIProfileAccount;
begin
  if cbAccounts.ItemIndex < 0 then
    Exit;
  ProfileAccount := oMAPIAccountManager.Account[cbAccounts.ItemIndex];
 
  ebUserName.Text := ProfileAccount.UserDisplayName;
  ebUserEmailAddress.Text := ProfileAccount.EmailID;
  cbAccountType.ItemIndex := Integer(ProfileAccount.AccountType);
 
  ebIncomingServer.Text := ProfileAccount.IncomingServer;
  ebOutgoingServer.Text := ProfileAccount.OutgoingServer;
 
  ebLogonUserName.Text := ProfileAccount.IncomingLoginName;
  cbSPA.Checked := ProfileAccount.UseIncomingSPA;
 
  ebMailAccount.Text := ProfileAccount.AccountName;
  ebOrganization.Text := ProfileAccount.Organization;
  ebReplayEmail.Text := ProfileAccount.POP3ReplayAddress;
 
  cbSMTPReqAuth.Checked := ProfileAccount.UseOutgoingUseAuthentication;
 
  ebUserNameSMTP.Text := ProfileAccount.OutgoingLoginName;
  cbOutgoingSPA.Checked := ProfileAccount.UseOutgoingSPA;
 
  ebPOP3Port.Text := IntToStr(ProfileAccount.IncomingPort);
  cbIncomingSSL.Checked := ProfileAccount.UseIncomingSSL;
  ebSMTPPort.Text := IntToStr(ProfileAccount.OutgoingPort);
  cbEncrType.ItemIndex := ProfileAccount.SMTPEncryptConnType;
  ebServerTimeOuts.Text := IntToStr(ProfileAccount.TimeOut);
 
  ebUserNameSMTP.Text := ProfileAccount.OutgoingLoginName;
  rbUseSameSettings.Checked :=
    ProfileAccount.OutgoingServerAuthenticationType = 0;
  rbSMTPLogOnUsing.Checked :=
    ProfileAccount.OutgoingServerAuthenticationType = 1;
  rbLogonBefore.Checked := ProfileAccount.OutgoingServerAuthenticationType = 2;
 
  cbRememberSMTPPassword.Checked := ProfileAccount.OutgoingRememberPassword;
  seDays.Value := HiWORD(ProfileAccount.AccountFlags and $FFFF0000);
  cbLeaveCopy.Checked :=
    Bool(LoWORD(ProfileAccount.AccountFlags and $0000FFFF) and 1);
  cbRemoveFromServer.Checked :=
    Bool(LoWORD(ProfileAccount.AccountFlags and $0000FFFF) and 2);
  cbRemoveDeleted.Checked :=
    Bool(LoWORD(ProfileAccount.AccountFlags and $0000FFFF) and 4);
end;
 
 
procedure TFrmAccounts.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  btDisplayAccounts.Enabled := False;
  btNewAccount.Enabled := False;
 
  cbAccounts.Items.Clear;
 
  if Assigned(oMAPIAccountManager) then
    FreeAndNil(oMAPIAccountManager);
  ReleaseMapiSession(MAPISession);
end;
 
 
procedure TFrmAccounts.FormCreate(Sender: TObject);
begin
{$IF DEFINED (WIN64)}
  Self.Caption := Self.Caption + ' - WIN64';
{$ELSE}
  Self.Caption := Self.Caption + ' - WIN32';
{$IFEND}
  oMAPIAccountManager := nil;
  MAPISession := nil;
end;
 
 
end.

 

 

Copyright © 1999 - 2021 IMIBO
Privacy Statement