Indy 9
TIdSMTPServer
Hierarchy, Properties, Methods, Events, See Also, Unit: IdSMTPServer
Implements a multi-thread SMTP Server.
TIdSMTPServer = class(TIdTCPServer)
Unit
IdSMTPServer
Description
TIdSMTPServer is a TIdTCPServer descendant that specifies properties and methods needed to implement a multi-threaded SMTP (Simple Mail Transfer Protocol) server, as described in the Internet Standrds documents:

  • RFC 2821 - Simple Mail Transfer Protocol [SMTP] (http://www.rfc-editor.org/rfc/rfc2821.txt)

  • RFC 1869 - SMTP Service Extensions (http://www.rfc-editor.org/rfc/rfc1869.txt)

  • RFC 2554 - SMTP Service Extension for Authentication (http://www.rfc-editor.org/rfc/rfc2554.txt)

TIdSMTPServer allows control over basic server options and configuration using properties like AllowEHLO, NoDecode, ReceiveMode, and Messages. TIdSMTPServer also exposes event handlers used for receiving incoming mail data like OnReceiveRaw, OnReceiveMessage, and OnReceiveMessageParsed.

TIdSMTPServer allows control over operational features of the server implementation using the command handler architecture and optional event handlers, including:


TIdSMTPServer.AllowEHLO
TIdSMTPServer, See Also
Indicates if the server implements the EHLO command.
property AllowEHLO: boolean;
Description
AllowEHLO is a Boolean property that indicates if the SMTP server implements the Extended HELLO (EHLO) command verb used to identify the SMTP client to the SMTP server. When AllowEHLO is True, it is implied that the SMTP server implements one or more of the SMTP service extensions.

AllowEHLO is used in the TIdSMTPServer.CommandEHLO command event handler when the SMTP client has issues the SMTP EHLO command. When AllowEHLO is True, the server will send the values in Messages.Greeting.EHLOReply that indicate the server capabilities. When AllowEHLO is False, the server will send the value in Messages.Greeting.EHLONotSupported to the SMTP client connection.


TIdSMTPServer.AuthMode
TIdSMTPServer, See Also
Indicates Authorization is used for the client connection prior to accepting MAIL data from the client connection.
property AuthMode: Boolean;
Description
AuthMode is a Boolean property that indicates if the SMTP server implementation requires authorization and/or authentication for client connections. AuthMode is used in the command handler for the SMTP MAIL command to determine if the threaded client has identified itself to the server using HELO or EHLO, and must be logged in prior to sending SMTP mail data. When AuthMode is True, the server will send the Messages.NotLoggedIn protocol reply if the client connection is not logged in after the OnCommandAUTH event handler is triggered.

The default value for AuthMode is False as assigned in the Create constructor. The server implementation can change the value in AuthMode prior to setting Active to True.


TIdSMTPServer.Messages
TIdSMTPServer
Represents replies that can be sent in responses to SMTP command verbs.
property Messages: TIdSMTPMessages;
Description
Messages is a TIdSMTPMessages property that represents various replies that can be sent by the SMTP server in responses to SMTP command verbs. Messages is used to assign the text for the ReplyNormal property in CommandHandler instances. Messages is also used in various command action handlers to construct response to the client connection.

TIdSMTPServer.NoDecode
TIdSMTPServer, See Also
Indicates if the server can parse incoming message headers.
property NoDecode: Boolean;
Description
NoDecode is a Boolean property that indicates if the SMTP server should parse headers in incoming messages into TIdMessage instances. NoDecode is used in the command action handler for the SMTP DATA command verb

NoDecode has significance when ReceiveMode contains the value rmMessageParsed, indicating that incoming messages are loaded and processed into a TIdMessage instance. NoDecode is he default vaLue that the processed message will have assigned to the TIdMessage.NoDecode property for the incoming message.

Notes
NoDecode does not apply to values in the message body.

Applications must assign a procedure to the OnReceiveMessageParsed event handler to allow subsequent handling of the message instance or email addresses in the message recipient list.


TIdSMTPServer.NoEncode
TIdSMTPServer
Indicates if encoding is allowed when processing mail data from a client connection.
property NoEncode: Boolean;
Description
NoEncode is a Boolean property that indicates if encoding is allowed when processing data received from a threaded SMTP client connection using the SMTP DATA command. NoEncode indicates the value that be used in the TIdMessage.NoEncode property for the parsed mail message when ReceiveMode is rmMessageParsed. Set NoDecode to indicate if decoding is allowed for parsed mail messages.

Note: NoEncode and NoDecode are not used when ReceiveMode contains a value other than rmMessageParsed.


TIdSMTPServer.RawStreamType
TIdSMTPServer, See Also
Indicates the stream class used when reading mail data from a client connection.
property RawStreamType: TIdStreamType;
Description
RawStreamType is a TIdStreamType property that indicates the TStream descendant class type to be used when reading mail data from a client connection. RawStreamType is used in the command handler for the SMTP DATA Command, and allows the server to determine the TStream descendant to use when capturing mail data from the threaded client connection.

TIdSMTPServer.ReceiveMode
TIdSMTPServer
Indicates the method used to receive and process incoming mail data.
property ReceiveMode: TIdSMTPReceiveMode;
Description
ReceiveMode is a TIdSMTPReceiveMode property that indicates the method used when handling incoming messages on the SMTP server. ReceiveMode is used in the command action handler for the SMTP DATA command verb.

When ReceiveMode contains rmRaw, incoming mail is read from the threaded client connection using the Capture method to store RFC message data in a TStream. Using rmRaw requires that a procedure be assigned to the OnReceiveRaw event handler to allow processing the stream for email addresses in the recipient list. If OnReceiveRaw is unassigned, an EIdTCPServerError exception will be raised.

When ReceiveMode contains rmMessage, incoming mail is read from the threaded client connection using the Capture method to store RFC message headers in a TIdMessage instance. Using rmMessage requires that a procedure be assigned to the OnReceiveMessage event handler to allow processing the TidMessage instance for email addresses in the recipient list. If OnReceiveMessage is unassigned, an EIdTCPServerError exception will be raised.

When ReceiveMode contains rmMessageParsed, incoming mail is read from the threaded client connection using a method similar to rmMessage. rmMessageParsed sets the NoDecode property for the TIdMessage instance to the value used in the SMTP server NoDecode property. rmMessageParsed also reconciles email addresses in the recipient list to determine the addresses which are stored in the BCCList for the TIdMessage instance. Using rmMessageParse requires that a procedure be assigned to the OnReceiveMessageParsed event handler to allow processing the TIdMessage instance for email addresses in the recipient list. If OnReceiveMessageParsed is unassigned, an EIdTCPServerError exception will be raised.


TIdSMTPServer.Create
TIdSMTPServer, See Also
Constructor for the object instance.
constructor Create(AOwner: TComponent); override;
Parameters
AOwner: TComponent
Owner of the object instance.
Description
Create is the constructor for the object instance, and calls the inherited Create method to initialize property values. Create sets the value of DefaultPort to 25 as used by convention in the SMTP protocol.

Create assigns TIdSMTPServerThread to ThreadClass to indicate the class used to create threads of execution for new SMTP client connections.

Create assigns the default values for the Greeting property, used when new client connections are established, and the ReplyUnknownCommand property, used when an unknown SMTP command is received by the SMTP server.

Create also initializes a group of TIdCommandHandler instances in CommandHandlers used to implement SMTP server commands when CommandHandlersEnabled is True. The commands and command event procedures in the default SMTP server implementation include:

  • HELP - CommandHELP

  • SOML - CommandSOML

  • SEND - CommandSEND

  • SAML - CommandSAML

  • VRFY - CommandVRFY

  • EXPN - CommandEXPN

  • TURN - CommandTURN

  • RSET - CommandRSET

  • DATA - CommandData

  • HELO - CommandHELO

  • EHLO - CommandEHLO

  • MAIL - CommandMail

  • NOOP - (None Required)

  • QUIT - (Sets Disconnect to True)

  • RCPT - CommandRcpt

TIdSMTPServer.Destroy
TIdSMTPServer, See Also
Frees the object instance.
destructor Destroy; override;
Description
Destroy is the destructor for the object instance. Destroy frees resources allocated to the Message property in the Create constructor, and calls the inherited Destroy method.

TIdSMTPServer.SetMessages
TIdSMTPServer, See Also
Assigns new values to the Message property.
procedure SetMessages(AValue: TIdSMTPMessages);
Parameters
AValue: TIdSMTPMessages
Messages to be assigned to the property.
Description
SetMessages is a public procedure used as the write access specifier for the Messages property. SetMessages calls the Assign method for the TIdSMTPMessages instance using the values specified in AValue.

TIdSMTPServer.CheckUser
TIdSMTPServer, See Also
Event handler signalled when authenticating a client connection.
property CheckUser: TUserHandler;
Description
CheckUser is a TUserHandler property that represents the event handler signalled when a TIdCommandHandler is used to perform authentication for a threaded SMTP client connection. CheckUser receives arguments that include the TIdCommand being executed, the Username and Password from the client thread, and an Accepted flag to indicate if the user authentication is valid.

Applications must assign a propcedure to the event handler to allow responding to the event notification, and to implement the processing required to perform authorization of the client account.

Set the value of the Accepted argument to True to indicate successful authentication, or False when the Username or Password cannot be authenticated. When CheckUser is not assigned, the account authentication is always accepted.


TIdSMTPServer.OnCommandAUTH
TIdSMTPServer
Event handler signalled to allow authentication using custom protocols and methods.
property OnCommandAUTH: TBasicHandler;
Parameters
ASender
Command generating the event notification.
Description
OnCommandAUTH is a TBasicHandler property that represents the command event handler used to implement the SMTP AUTH command verb, and allows the server to perform custom authentication methods or protocols not found in the default server implementation in CommandHandlers.

OnCommandAUTH is used in the AUTH Command event handler when the client connection has provided identication using the EHLO command. Applications must assign a procedure to the OnCommandAUTH event handler to allow responding to the event notification. When OnCommandAUTH is not assigned, the server uses the internal authorization mechanism, equivalent to AUTH LOGIN, and the CheckUser event handler.

Note: When the client connection uses the HELO command, authentication is not performed according to the SMTP protocol.


TIdSMTPServer.OnCommandEXPN
TIdSMTPServer
Event handler signalled to implement expanding email addresses or mailing list membership.
property OnCommandEXPN: TBasicHandler;
Parameters
ASender
Command generating the event notification.
Description
OnCommandEXPN is a TBasicHandler property that represents the event handler signalled when executing the SMTP EXPN command verb using CommandHandlers. OnCommandEXPN allows the server to implement the processing needed to expand the email or mailing list address provided in the TIdCommand in ASender a return the email addresses that are members of the list.

Application must assign a procedure to the OnCommandEXPN event handler to allow responding to the event notification. When OnCommandEXPN is unassigned, the server will send the text in Messages.ErrorReply to the client connection.

An SMTP server may choose to disable EXPN for security reasons. EXPN has been used by spammers to harvest email addresses. An SMTP server should also use some type of authentication mechanism, like OnCommandAUTH, to prevent this type of abuse.

When EXPN is enabled, the implementation must not indicate an email address as verified when it has not been tested.


TIdSMTPServer.OnCommandHELP
TIdSMTPServer
Event handler signalled to implement the SMTP Help command.
property OnCommandHELP: TBasicHandler;
Parameters
ASender
Command generating the event notification.
Description
OnCommandHELP is a TBasicHandler property that represents the event handler signalled when executing the SMTP HELP command verb using a CommandHandler. OnCommandHELP implements the processign needed to send the list of commands supported by the SMTP server to an SMTP client connection.

The server implementation must assign a procedure to the OnCommandHELP event handler to allow responding to the event notification. When OnCommandHELP is unassigned, the text in Messages.ErrorReply is sent to the client connection.

OnCommandHELP can be used to request more specific help detail by including an optional parameter value in the TIdCommand.Params found in ASender.


TIdSMTPServer.OnCommandMAIL
TIdSMTPServer
Event handler signalled during execution of the SMTP MAIL command.
property OnCommandMAIL: THasAddress2;
Parameters
Accept
Indicates if the email address is accepted or rejected.
ASender
Command generating the event noticication.
EMailAddress
Origin email address for the message.
Description
OnCommandMAIL is a THasAddress2 property that represents the event handler signalled when executing the SMTP MAIL command using CommandHandlers for the threaded client connection.

The SMTP MAIL command is used to initiate a mail transaction for dellivery of mail data to the SMTP server. The SMTP server will then decide if the mail data can be deliverd to mailboxes or passed to another SMTP server. If service extensions were negotiated, using AllowEHLO, the MAIL command may also carry parameters associated with a particular service extension.

The SMTP server provides an internal MAIL command action handler that insures that the client connection has been identified using the EHLO or HELO command prior to processing arguments in the MAIL command. When no client identification has been provided, the text in the Messages.Greeting.NoHello is sent to the client connection.

If the client connection has been identified to the SMTP server, the command action handler parses the origin email address from TIdCommand.UnparsedParams values found in ASender. When no client identification has been provided, the text in the Messages.Greeting.NoHello is sent to the client connection.

The SMTP server implementation must assign a procedure to the OnCommandMail event handler to allow responding to the THasAddress2 event notification. The event handler is used to validate the email address that will be used in the TIdSMTPServerThread.From property for the threaded client connection, and indicate if the address has been accepted. The event handler must assign the email address to the ASender.From property when Accepted is True. If the email address for thesender is not accepted, the text in Messages.RcpReplies.AddressErrorReply is sent to the client connection.

When OnCommandMail is unassigned, the email address parsed by the command action handler is assigned to the ASender.FRom property, and the text in Messages.RcpReplies.AddressOKReply is sent to the client connection.


TIdSMTPServer.OnCommandRCPT
TIdSMTPServer
Event handler signalled during execution of the SMTP RCPT command.
property OnCommandRCPT: THasAddress;
Parameters
Accept
Indicates if the address is accepted.
ASender
The command instance generating the event.
CustomError
Message to use when a protocol error occurs.
EMailAddress
Email address received in the command.
ToForward
Indicates if the address requires forwarding.
Description
OnCommandRCPT is a THasAddress property that represents the event handler signalled when executing the SMTP RCPT command using CommandHandlers for the threaded client connection.

The SMTP RCPT command is used to identify an individual recipient of the mail data. Multiple recipients are specified by multiple use of this command. The argument field contains an email address that is the destination mailbox for the mail data, and may contain optional parameters.

If service extensions were negotiated, when ALlowEHLO is True, the RCPT command may also carry parameters associated with a particular service extension offered by the server. The client must not transmit parameters other than those associated with a service extension offered by the server in its EHLO response.

The SMTP server implementation provides a RCPT command action handler that performs processing required prior to signalling the OnCommandRCPT event handler. The command action handler insures that the client connection has been identified using the HELO or EHLO command. If the client has not been identified, the text in Messages.Greeting.NoHello is sent to the client connection.

The RCPT command action handler parses values in ASender.UnparsedParams, and constructs a email address that can be used in the OnCommandRCPT event handler.

The SMTP server implementation must assign a procedure to the OnCommandRCPT event handler top allow responding to the TIdHasAddress event notification. The OnCOmmandRCPT event handler is responsible for determining if subsequent mail data can be Accepted, if delivery of mail data requires Forwarding, and assigning any CustomError messages that occur during the event handler.

When no error messages are generated in OnCommanRCPT, the email addresses are assigned to ASender.RcptList for the threaded client connection. If error messages are detected, the text in the errror message is sent to the client connection.

When OnCommandRCPT is unassigned, the parsed email addresses are assigned to ASender.RcptList, and the text in Messages.RcpReplies.AddressOkReply is sent to client connection.


TIdSMTPServer.OnCommandSAML
TIdSMTPServer
Event handler signalled to implement the SMTP SAML command.
property OnCommandSAML: TBasicHandler;
Parameters
ASender
Command generating the event notification.
Description
OnCommandSAML is a TBasicHandler property that represents the event handler signalled to initiate a mail transaction in which the mail data is delivered to one or more terminals or mailboxes. The SMTP SAML command allows delivery of mail data to a terminal, when the user is connected to the host and accepts terminal messages, or to a recipient's mailbox.

OnCommandSAML will use the list of hosts or email addresses and the sender mailbox provided in the TIdCommand.Params found in ASender. When a list of hosts is present, they represent the reverse source route used to relay the mail message., and is used to return non-delivery notices for the message. The first host in the list is the most recent relay.

The server implementation must assign a procedure to the OnCommandSAML event handler to allow responding to the event notification. When OnCommandSAML is unassigned, the text in Message.ErrorReply is sent to the client connection.


TIdSMTPServer.OnCommandSEND
TIdSMTPServer
Event handler signalled to implement the SMTP SEND command.
property OnCommandSEND: TBasicHandler;
Parameters
ASender
Command generating the event notification.
Description
OnCommandSEND is a TBasicHandler property that represents the event handler signalled when executing the SMTP SEND command verb using CommandHandlers. OnCommandSEND allows the SMTP server to initate a mail transaction where mail data is delivered to one or more terminals.

OnCommandSEND is used with the list of hosts and the sender email address found in the TIdCommand.Params values found in ASender.

When the list of hosts is present, it is a reverse source route and indicates that the mail was relayed through each host on the list. The first host in the list was the most recent relay. This list is used as a source route to return non-delivery notices to the sender.

An SMTP server implementation must assign a preocedure to the OnCommandSEND event handler to allow responding to the event noticication. When OnCommandSEND is unassigned, the text in Messages.ErrorReply is sent to the client connection.


TIdSMTPServer.OnCommandSOML
TIdSMTPServer
Event handler signalled to implement the SMTP SOML command.
property OnCommandSOML: TBasicHandler;
Parameters
ASender
Command generating the event notification.
Description
OnCommandSOML is a TBasicHandler property that represents the event handler signalled to initiate a mail transaction in which the mail data is delivered to one or more terminals or mailboxes. The SMTP SOML command allows delivery of mail data to a terminal, when the user is connected to the host and accepts terminal messages, or to a recipient's mailbox.

OnCommandSOML will use the list of hosts or email addresses and the sender mailbox provided in the TIdCommand.Params found in ASender. When a list of hosts is present, they represent the reverse source route used to relay the mail message., and is used to return non-delivery notices for the message. The first host in the list is the most recent relay.

The server implementation must assign a procedure to the OnCommandSOML event handler to allow responding to the event notification. When OnCommandSOML is unassigned, the text in Message.ErrorReply is sent to the client connection.


TIdSMTPServer.OnCommandTURN
TIdSMTPServer
Event handler signalled to implement the SMTP TURN command.
property OnCommandTURN: TBasicHandler;
Parameters
ASender
Command generating the event notification.
Description
OnCommandTURN is a TBasicHandler property that represents the event handler signalled when executing the SMTP TURN command verb. OnCommandTURN allows the server to perform role negotiation with another SMTP host, where the receiving server will begin to act as a sending server, or refuse the role negotioation.

The SMTP TURN command, described in RFC 821, raises important security issues since, in the absence of strong authentication of the host requesting that the client and server switch roles, it can easily be used to divert mail from its correct destination. Its use is deprecated in RFC 2821. SMTP systems should not use it unless the server can authenticate the client.


TIdSMTPServer.OnCommandVRFY
TIdSMTPServer
Event handler signalled to implement the SMTP VRFY command.
property OnCommandVRFY: TBasicHandler;
Parameters
ASender
Command generating the event notification.
Description
OnCommandVRFY is a TBasicHandler property that represents the event handle signalled when executing the SMTP VRFY command using CommandHandlers. OnCommandVRFY allows the SMTP server to verify that the TIdCommand.Params value specified in ASender contains a valid user name or email address for a mailbox on the SMTP server.

The SMTP server implementation must assign a procedure to the OnCommandVRFY event handler to allow responding to the event notification. When OnCommandVRFY is unassigned, the text in Messages.ErrorReply is sent to the client connection.


TIdSMTPServer.OnReceiveMessage
TIdSMTPServer, See Also
Event handler signalled when reading and parsin incoming mail into a message instance.
property OnReceiveMessage: TOnReceiveMessage;
Description
OnReceiveMessage is a TOnReceiveMessage property that represents the event handler signalled when a threaded client connection reads and processes incoming mail data. OnReceiveMessage is used in the SMTP DATA command event handler when ReceiveMode contains the value rmMessage.

The command event handler creates a TIdMessage instance to hold the values in the incoming data, and captures message headers found in the incoming mail.

Applications must assign a procedure to the OnReceiveMessage event handler to allow processing of the message header data or email addresses in the recipient list for the client connection. If OnReceiveMessage is unassigned, an EIdTCPServerError exception will be raised.

OnReceiveMessage must fully process the message instance containing the message headers, since the message instance will be freed prior to exiting from the DATA command action handler.


TIdSMTPServer.OnReceiveMessageParsed
TIdSMTPServer, See Also
Event handler signalled when reading and parsing incoming mail into a message instance, including message headers.
property OnReceiveMessageParsed: TOnReceiveMessage;
Description
OnReceiveMessageParsed is a TOnReceiveMessage property that represents the event handler signalled when a threaded client connection reads and processes incoming mail data. OnReceiveMessageParsed is used in the SMTP DATA command event handler when ReceiveMode contains the value rmMessageParsed.

The command event handler creates a TIdMessage instance to hold the values in the incoming data, and sets the value of NoDecode property in the message instance to the value used by the SMTP server. The command event handler also reads and parses message headers into their corresponding property values. The command event handler reconciles email addresses in the recipient list for the client connection to determine the addresses to include in the BCCList for the message instance.

Applications must assign a procedure to the OnReceiveMessageParsed event handler to allow processing of the message data or email addresses in the recipient list for the client connection. If OnReceiveMessageParsed is unassigned, an EIdTCPServerError exception will be raised.

OnReceiveMessageParsed must fully process the message instance containing the message headers and message body, since the message instance will be freed prior to exiting from the DATA command action handler.


TIdSMTPServer.OnReceiveRaw
TIdSMTPServer
Event handler signalled for incoming mail in a TMemoryStream.
property OnReceiveRaw: TOnReceiveRaw;
Parameters
ASender
Command generating the event notification.
RCPT
Recipients for the message.
VStream
Memory streamcontaining the message headers and body.
Description
OnReceiveRaw is a TOnReceiveRaw property that represents the event handler signalled to handle incoming mail from the command action handler for the SMTP DATA command. OnReceiveRaw allows the SMTP server to process RFC message data read using a TStream when ReceiveMode is rmRaw.

The DATA command action handler reads data from the threaded client connection using Capture to store message data prior to signalling the event handler.

Applications must assign a procedure to the OnReceiveRaw event handler to allow processing of the message data or email addresses in the recipient list for the client connection. If OnReceiveRaw is unassigned, an EIdTCPServerError exception will be raised.

OnReceiveRaw must fully process the stream containing the message headers and message body, since the stream will be freed prior to exiting from the DATA command action handler.


Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.