Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
ssh: HCkSsh;
mailman: HCkMailMan;
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 := CkSsh_Create();
success := CkSsh_Connect(ssh,'ssh.example.com',22);
if (success = False) then
begin
Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
Exit;
end;
success := CkSsh_AuthenticatePw(ssh,'sshUser','sshPassword');
if (success = False) then
begin
Memo1.Lines.Add(CkSsh__lastErrorText(ssh));
Exit;
end;
mailman := CkMailMan_Create();
// Configure the POP3 server connection. These connections will travel through the tunnel.
CkMailMan_putMailHost(mailman,'pop.example.com');
CkMailMan_putMailPort(mailman,995);
CkMailMan_putPopSsl(mailman,True);
CkMailMan_putPopUsername(mailman,'user@example.com');
CkMailMan_putPopPassword(mailman,'myPassword');
// Tell MailMan to route its connections through the already-connected Ssh object.
success := CkMailMan_UseSsh(mailman,ssh);
if (success = False) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
Exit;
end;
// POP3 operations now travel through the shared SSH connection.
count := CkMailMan_GetMailboxCount(mailman);
if (count < 0) then
begin
Memo1.Lines.Add('Failed to get the mailbox count.');
end
else
begin
Memo1.Lines.Add('Mailbox count: ' + IntToStr(count));
end;
CkSsh_Disconnect(ssh);
CkSsh_Dispose(ssh);
CkMailMan_Dispose(mailman);