Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Use an Existing Ssh Object as the Tunnel
See more POP3 Examples
Demonstrates the Chilkat MailMan.UseSsh method, which configures MailMan to use an existing SSH tunnel provided by an Ssh object for its SMTP and POP3 connections. This example connects and authenticates an Ssh object separately, hands it to MailMan, and then performs a POP3 operation through it.
Background: Rather than having MailMan open its own tunnel (
SshOpenTunnel), you can manage the SSH connection yourself and share it. That is valuable when several Chilkat objects must reach the same remote network — they all ride one authenticated SSH connection instead of each opening its own — and it enables advanced setups such as multi-hop SSH, where the Ssh object is already chained through intermediate servers.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.MailMan,
Chilkat.Ssh;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ssh: TSsh;
mailman: TMailMan;
count: Integer;
begin
success := False;
// Demonstrates the MailMan.UseSsh method, which configures MailMan to use an existing SSH
// tunnel provided by an Ssh object for its SMTP and POP3 connections.
// Establish the SSH connection separately, using an Ssh object.
ssh := TSsh.Create;
success := ssh.Connect('ssh.example.com',22);
if (success = False) then
begin
WriteLn(ssh.LastErrorText);
Exit;
end;
success := ssh.AuthenticatePw('sshUser','sshPassword');
if (success = False) then
begin
WriteLn(ssh.LastErrorText);
Exit;
end;
mailman := TMailMan.Create;
// Configure the POP3 server connection. These connections will travel through the tunnel.
mailman.MailHost := 'pop.example.com';
mailman.MailPort := 995;
mailman.PopSsl := True;
mailman.PopUsername := 'user@example.com';
mailman.PopPassword := 'myPassword';
// Tell MailMan to route its connections through the already-connected Ssh object.
success := mailman.UseSsh(ssh);
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
// POP3 operations now travel through the shared SSH connection.
count := mailman.GetMailboxCount();
if (count < 0) then
begin
WriteLn('Failed to get the mailbox count.');
end
else
begin
WriteLn('Mailbox count: ' + count);
end;
ssh.Disconnect();
ssh.Free;
mailman.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.