Delphi DLL
Delphi DLL
Use an Existing Socket SSH Tunnel
See more SMTP Examples
Demonstrates the Chilkat MailMan.UseSshTunnel method, which configures MailMan to use an existing SSH tunnel provided by a Socket object for its SMTP and POP3 connections. This example opens and authenticates a tunnel on a Socket, hands it to MailMan, and then verifies an SMTP login through it.
Background: Sharing one already-established SSH tunnel across objects avoids opening (and authenticating) a separate SSH connection for every component that needs to reach the remote network. Here the tunnel lives on a
Socket object, which MailMan then routes its SMTP/POP3 traffic through. It is the Socket-based sibling of UseSsh, which shares an Ssh object instead.Chilkat Delphi DLL Downloads
var
success: Boolean;
sshTunnel: HCkSocket;
mailman: HCkMailMan;
begin
success := False;
// Demonstrates the MailMan.UseSshTunnel method, which configures MailMan to use an existing
// SSH tunnel provided by a Socket object for its SMTP and POP3 connections.
// Open and authenticate the SSH tunnel using a Socket object.
sshTunnel := CkSocket_Create();
success := CkSocket_SshOpenTunnel(sshTunnel,'ssh.example.com',22);
if (success = False) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(sshTunnel));
Exit;
end;
success := CkSocket_SshAuthenticatePw(sshTunnel,'sshUser','sshPassword');
if (success = False) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(sshTunnel));
Exit;
end;
mailman := CkMailMan_Create();
// Configure the SMTP server connection. These connections will travel through the tunnel.
CkMailMan_putSmtpHost(mailman,'smtp.example.com');
CkMailMan_putSmtpPort(mailman,465);
CkMailMan_putSmtpSsl(mailman,True);
CkMailMan_putSmtpUsername(mailman,'user@example.com');
CkMailMan_putSmtpPassword(mailman,'myPassword');
// Tell MailMan to route its connections through the existing tunnel.
success := CkMailMan_UseSshTunnel(mailman,sshTunnel);
if (success = False) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
Exit;
end;
// SMTP operations now travel through the shared SSH tunnel.
success := CkMailMan_VerifySmtpLogin(mailman);
if (success = False) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
Exit;
end;
Memo1.Lines.Add('Authenticated with the SMTP server through the SSH tunnel.');
CkSocket_Dispose(sshTunnel);
CkMailMan_Dispose(mailman);