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)
inherits from eTLSClientError
constructor CreateReply(aCode: Integer; const aCommand, aText: string);
property ReplyCode: Integer read fReplyCode;
inherits from TsmCustomTLSClient
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Open;
procedure Close;
procedure SendMail(aMessage: TsmEmail); overload;
procedure SendMail(const aFrom: string; aRecipients: TStrings; const aData: tBytes); overload;
procedure SetPassword(const aValue: string);
property Password: iSecretKey read fPassword write fPassword;
property Extensions: TStrings read GetExtensions;
function SupportsExtension(const aName: string): Boolean;
function ExtensionParams(const aName: string): string;
property ServerMaxSize: Int64 read fServerMaxSize;
property LastReplyCode: Integer read fLastReplyCode;
property LastReplyText: string read GetLastReplyText;
property Authenticated: Boolean read fAuthenticated;
property SessionOpen: Boolean read fSessionOpen;
property Stage: tSmtpDeliveryStage read fStage;
function TryMailFrom(const aFrom: string): Integer;
property HeloName: string read fHeloName write fHeloName;
property UserName: string read fUserName write fUserName;
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;
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;
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;
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).
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.