Indy 9
|
TIdSMTPServer = class(TIdTCPServer)
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:
property AllowEHLO: boolean;
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.
property AuthMode: Boolean;
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.
property Messages: TIdSMTPMessages;
property NoDecode: Boolean;
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.
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.
property NoEncode: Boolean;
Note: NoEncode and NoDecode are not used when ReceiveMode contains a value other than rmMessageParsed.
property RawStreamType: TIdStreamType;
property ReceiveMode: TIdSMTPReceiveMode;
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.
constructor Create(AOwner: TComponent); override;
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:
destructor Destroy; override;
procedure SetMessages(AValue: TIdSMTPMessages);
property CheckUser: TUserHandler;
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.
property OnCommandAUTH: TBasicHandler;
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.
property OnCommandEXPN: TBasicHandler;
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.
property OnCommandHELP: TBasicHandler;
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.
property OnCommandMAIL: THasAddress2;
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.
property OnCommandRCPT: THasAddress;
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.
property OnCommandSAML: TBasicHandler;
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.
property OnCommandSEND: TBasicHandler;
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.
property OnCommandSOML: TBasicHandler;
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.
property OnCommandTURN: TBasicHandler;
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.
property OnCommandVRFY: TBasicHandler;
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.
property OnReceiveMessage: TOnReceiveMessage;
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.
property OnReceiveMessageParsed: TOnReceiveMessage;
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.
property OnReceiveRaw: TOnReceiveRaw;
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.