Delphi DLL
Delphi DLL
Close a Persistent SMTP Connection
See more SMTP Examples
Demonstrates the Chilkat MailMan.CloseSmtpConnection method, which explicitly closes the current SMTP connection. Before closing the socket, Chilkat sends the SMTP QUIT command so the server can end the session cleanly. This example opens a connection and then closes it.
Background: This is the companion to
OpenSmtpConnection and completes the "open once, send many, close once" batch pattern. Sending QUIT before dropping the socket is proper SMTP etiquette: it tells the server you are finished so it can release resources gracefully rather than treating the disconnect as an abrupt drop.Chilkat Delphi DLL Downloads
var
success: Boolean;
mailman: HCkMailMan;
begin
success := False;
// Demonstrates the MailMan.CloseSmtpConnection method, which explicitly closes the current
// SMTP connection. Before closing the socket, Chilkat sends the SMTP QUIT command.
mailman := CkMailMan_Create();
// Configure the SMTP server connection.
CkMailMan_putSmtpHost(mailman,'smtp.example.com');
CkMailMan_putSmtpPort(mailman,465);
CkMailMan_putSmtpSsl(mailman,True);
CkMailMan_putSmtpUsername(mailman,'user@example.com');
CkMailMan_putSmtpPassword(mailman,'myPassword');
// Open a connection (which would be reused for multiple sends).
success := CkMailMan_OpenSmtpConnection(mailman);
if (success = False) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
Exit;
end;
// ... send emails here ...
// Explicitly close the SMTP connection (sends QUIT first).
success := CkMailMan_CloseSmtpConnection(mailman);
if (success = False) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
Exit;
end;
Memo1.Lines.Add('SMTP connection closed.');
CkMailMan_Dispose(mailman);