Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Mail.SMTPClient

An SMTP client (RFC 5321) for MESSAGE SUBMISSION (RFC 6409) on the
  TsmCustomTLSClient base: implicit TLS on port 465 (RFC 8314, the default
  and recommended shape) and STARTTLS on port 587 for the deployments -
  Microsoft 365 first among them - that offer nothing else. It sends
  TsmEmail messages or raw RFC 5322 octets; it is not an MTA: no MX
  resolution, no relaying, no queueing, no retry.

  THE RequireTLS CONTRACT, upheld as follows. Every protocol command goes
  through the base's public Send/SendLine/ReadLine, so the base's gate
  applies to this unit's own traffic: on a cleartext connection those raise
  unless the upgrade window is open or the consumer set RequireTLS False.
  Open confines the window to exactly the dialogue RFC 3207 needs - the
  greeting, EHLO, STARTTLS and its reply - and re-issues EHLO after the
  handshake because a capability list learned in cleartext is untrusted.
  When the server does not offer STARTTLS, Open fails while RequireTLS is
  in force, and proceeds in cleartext only after the consumer's deliberate
  RequireTLS := False. Two commands are stricter than the property:
  AUTHENTICATION REFUSES TO RUN WITHOUT TLS UNCONDITIONALLY (credentials
  never cross cleartext, whatever RequireTLS says - the TsmCustomHTTPSClient
  posture), while message submission honours RequireTLS := False.

  Errors are exceptions: a negative SMTP reply raises eSMTPClientError
  carrying the reply code and text, after a best-effort RSET so the session
  survives for another attempt. The last reply is always inspectable
  through LastReplyCode/LastReplyText.

Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)

Classes, interfaces and records

classeSMTPClientError

inherits from eTLSClientError

constructor CreateReply(aCode: Integer; const aCommand, aText: string); property ReplyCode: Integer read fReplyCode;
The SMTP reply code behind the failure, 0 when the failure was not a reply (timeout, malformed reply, refused precondition).

classTsmCustomSMTPClient

inherits from TsmCustomTLSClient

constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Open;
Connects and brings the session to the ready-to-submit state: TCP (+ TLS when ImplicitTLS), greeting, EHLO, STARTTLS + second EHLO on the upgrade path, and authentication when UserName is set. On any failure the connection is torn down and the exception re-raised. » member page
procedure Close;
QUIT (best effort) and disconnect. Safe to call at any time. » member page
procedure SendMail(aMessage: TsmEmail); overload;
Submits a message: reverse path from Sender (falling back to From), forward paths from To, Cc and Bcc, and the Bcc header STRIPPED from the transmitted octets - the recipients are blind precisely because the copy on the wire does not name them. The message octets are dot-stuffed and CRLF-normalized here. » member page
procedure SendMail(const aFrom: string; aRecipients: TStrings; const aData: tBytes); overload;
The explicit-envelope form: aFrom and aRecipients are bare addr-specs; aData is the complete RFC 5322 message. No Bcc handling is applied - with an explicit envelope the caller owns that. » member page
procedure SetPassword(const aValue: string);
Wraps aValue in a wiped-on-release iSecretKey. The interface-typed Password property is the primary API; this is the convenience for callers holding a plain string (which this method cannot wipe). » member page
property Password: iSecretKey read fPassword write fPassword;
The credential used by DoAuthenticate, held only in wiped storage. » member page
property Extensions: TStrings read GetExtensions;
The EHLO keyword lines (first token = extension name), refreshed on every EHLO - after STARTTLS they reflect the TLS-protected answer. » member page
function SupportsExtension(const aName: string): Boolean; function ExtensionParams(const aName: string): string;
The parameter text after the keyword, '' when absent. » member page
property ServerMaxSize: Int64 read fServerMaxSize;
The SIZE extension's announced limit, 0 when unknown. » member page
property LastReplyCode: Integer read fLastReplyCode; property LastReplyText: string read GetLastReplyText; property Authenticated: Boolean read fAuthenticated;
True from the 235 reply until the transport drops. » member page
property SessionOpen: Boolean read fSessionOpen;
True from Open's completion until Close or a transport drop. » member page
property Stage: tSmtpDeliveryStage read fStage;
How far THIS session got. Open resets it to sdsSession; the session advances it; it is NOT cleared when the transport drops, so after Open or SendMail raised and tore the connection down a caller can still tell where it stopped - without reading the server's text, which is the only other place th... Full description »
function TryMailFrom(const aFrom: string): Integer;
MAIL FROM:<aFrom> AND NOTHING AFTER IT, so a deployment can ask "would this server take mail from this sender" without submitting a message. Full description »
property HeloName: string read fHeloName write fHeloName;
The EHLO/HELO argument. Set it to this host's public FQDN; the default 'localhost' is accepted by submission servers, which RFC 6409 directs to identify clients by authentication rather than by this string. » member page
property UserName: string read fUserName write fUserName;
Authentication runs when this is non-empty. The password travels separately, through Password or SetPassword. » member page
property AuthMechanism: tSMTPAuthMechanism read fAuthMechanism write fAuthMechanism default samAuto; property ReplyTimeout: Cardinal read fReplyTimeout write fReplyTimeout default cSMTPDefaultReplyTimeout; property DataTimeout: Cardinal read fDataTimeout write fDataTimeout default cSMTPDefaultDataTimeout;
The wait for the reply that ends DATA - the server is storing the message, its slowest moment. » member page

classTsmSMTPClient — component reference

inherits from TsmCustomSMTPClient

The self-contained tier: creates and owns its TLS engine, so a client dropped on a form works with no other component wired up. Reach into TLSServer for trust anchors (LoadRootCertsFromFile) and, for mutual TLS, a client identity (ImportFromPFX).

property TLSServer: TsmSimpleTLSInternalServer read GetTLSServer write SetOwnTLSServer;
Created and owned here; the setter refuses a foreign component - see TsmTLSClient, whose tier pattern this mirrors. » member page

classTsmAdvancedSMTPClient — component reference

inherits from TsmCustomSMTPClient

The tier that takes an EXTERNAL engine, so several clients share one set of trust anchors; nil falls back to GlobalServer.

property TLSServer;

Types (enumerations, sets, aliases)

enumtSMTPAuthMechanism

samAuto picks PLAIN when the server advertises it, else LOGIN; the explicit members force one mechanism (sent even when unadvertised - some servers only reveal AUTH after TLS or not at all).

  tSMTPAuthMechanism = (samAuto, samPlain, samLogin);

enumtSmtpDeliveryStage

HOW FAR A SESSION GOT. Declared here, in the unit whose own code moves it, and re-exported by StreamSec.Mail.SMTPSpool so that a consumer sees one type rather than two enumerations that can drift apart.
sdsSession connecting, TLS, the greeting, EHLO, STARTTLS - nothing of the credential and nothing of the message had been offered
sdsAuth the credential was being offered
sdsMail the session was open and MAIL FROM was being sent - the reverse path is the CONFIGURED sender, so nothing recipient-specific has crossed the wire yet
sdsRcpt a recipient had been named
sdsData the body was being sent, or the message was accepted THE BOUNDARY THAT MATTERS to a consumer is the one between sdsMail and
sdsRcpt: at or before sdsMail a failure is the host's or the account's, from sdsRcpt on it may be this one letter's. A queue that abandons on the wrong side of it destroys good mail on an account fault, and a circuit breaker that counts the wrong side of it becomes a denial-of-service handle for whoever gets to choose a recipient.

  tSmtpDeliveryStage = (sdsSession, sdsAuth, sdsMail, sdsRcpt, sdsData);