Indy 9
Hierarchy, Properties, Methods, Events, See Also, Unit: IdSMTP
Implements a Simple Mail Transfer Protocol client.
TIdSMTP = class(TIdMessageClient)
TIdSMTP is a TIdMessageClient descendant that implements a Simple Mail Transfer Protocol or SMTP client, as described in the Internet Standards documents:

  • RFC 821 - Simple Mail Transfer Protocol [SMTP] (

  • RFC 1869 - SMTP Service Extensions (

  • RFC 2554 - SMTP Service Extension for Authentication (

Use TIdPOP3 or TIdIMAP4 to retrieve E-Mail messages from a mail server to the user's computer.

Authentication type required to connect to the SMTP host.
property AuthenticationType: TAuthenticationType;
AuthenticationType is a TAuthenticationType property that specifies the authentication type to use when accessing the E-Mail server. AuthenticationType can contain one of the following values:

  • atNone - no authentication is required.

  • atLogin - simple username and password authentication is required (AUTH LOGIN).

You can find the authentication mechanisms supported on the E-Mail server identified in Host by using AuthSchemesSupported.

List of supported authentication methods for the SMTP server.
property AuthSchemesSupported: TStringList;
AuthSchemesSupported is a read-only TStringList property that contains the authentication methods supported by an SMTP Mail server. AuthSchemesSupported is valid only when you are connected to the server. Set AuthenticationType to the appropriate value for one of the authentication schemes supported on the SMTP server.

Note: Any given SMTP server can support authentication mechanisms which may not be implemented in TIdSMTP.

TIdSMTP, See Also
Identities the client connecting to an SMTP server.
property HeloName: string;
HeloName is a String property that represents the identity name of the client establishing a connection to the SMTP server using either the SMTP EHLO or HELO command verbs. HeloName is used in Connect to hail the SMTP server. when HeloName contains a blank value, LocalName is used when hailing the SMTP server.

TIdSMTP, See Also
Identifies the program that created a message.
property MailAgent: string;
MailAgent is a String property that identifies the name of a program used to create or transmit a message. MailAgent specifies your program name, and is placed in the SMTP 'X-Mailer' header in the Send method.

TIdSMTP, See Also
Specifies the password used for SMTP account authentication.
property Password;
Password is a String property that specifies the password used for SMTP account authentication. Username and Password are used by Authenticate when AuthenticationType is atLogin.

TIdSMTP, See Also
Indicates the SMTP client desires authetication type information from the SMTP server.
property UseEhlo: Boolean;
UseEhlo is a Boolean property that indicates the SMTP client desires authetication type information from the SMTP server. When UseEhlo is True, the client will connect with the SMTP EHLO greeting that instructs the server to send supported authentication types after the banner greeting.

UseEhlo is used in the Connect method prior to sending the value from HeloName (or LocalName) to the SMTP server. When UseEhlo is True, the client identification is sent using the SMTP EHLO command. Authentication types supported by the server are captured upon successful completion of the EHLO command. When UseEhlo is False, the SMTP HELO command is used for client identification.

Note: Changing the value of UseEhlo from True to False forces the AuthenticationType property to be reset to the value atNone. An application must set the correct value for AuthenticationType after changing UseEhlo from True to False.

TIdSMTP, See Also
Specifies the user account for the SMTP server.
property Username;
Username is a String property that specifies the user name used to log on to the SMTP Server. Username and Password are used, in Authenticate, to perform account verification when AuthenticationType is atLogin.

Copies property values to the current object instance.
procedure Assign(Source: TPersistent); override;
Source: TPersistent
Object instance containing property values to be copied.
Assign is a procedure that allows an persistent object instance to copy property values from another persistent object instance to the current instance.

Assign will load the following property values:

Performs account authentication on the SMTP server.
function Authenticate: Boolean; virtual;
Return Value
Boolean - True on success.
Authenticate is a Boolean function that performs account authentication on the SMTP server. Authenticate returns True when successful, or False if authentication failed.

You must specify the AuthenticationType before calling the Authenticate method. Authenticate should be called only once for a SMTP session.

Send will also call Authenticate before transmission of an E-Mail message, if the SMTP session has not been authenticated.

When AuthenticationType is atLogin, Authenticate sends the SMTP AUTH LOGIN command followed by the Base64-encoded values for Username and Password to the server.

Opens a connection to the SMTP server.
procedure Connect(const ATimeout: Integer = IdTimeoutDefault); override;
const ATimeout: Integer = IdTimeoutDefault
Connection timeout in milliseconds. Default value is IdTimeoutDefault.
Connect is a procedure that opens a connection to the SMTP server using the Host and Port properties. An exception will be raised if the connection fails or returns an invalid SMTP response code.

After establishing the socket connection, Connect will clear AuthSchemesSupported. Connect hails the server using either the HeloName or the LocalName properties using either the SMTP EHLO or HELO commands. When the EHLO command is supported on the SMTP server, AuthSchemesSupported will be loaded.

If an exception is raised in Connect, the SMTP client will call Disconnect and the exception will be re-raised.

TIdSMTP, See Also
Constructor for the object instance.
constructor Create(AOwner: TComponent); override;
AOwner: TComponent
Owner of the object instance.
Create is the constructor for the object instance. Create initializes AuthSchemesSupported to ignore duplicate entries, and sets Port to the default SMTP port number (IdPORT_SMTP).

TIdSMTP, See Also
Frees the object instance.
destructor Destroy; override;
Destroy is the destructor for the object instance. Destroy clears and releases the AuthSchemesSupported property prior to calling the inherited Destroy method.

Closes the SMTP session.
procedure Disconnect; override;
Disconnect is a procedure that closes the SMTP session. When Connected is True, the SMTP QUIT command is used to inform the server that the session will be ended. Disconnect calls the inherited Disconnect method, and indicates that the SMTP session has not been previously authenticated.

TIdSMTP, See Also
Determines group membership for a mailing list or mailbox alias.
procedure Expand(AUserName: String; AResults: TStrings); virtual;
AUserName: String
Mail list or alias to be expanded.
AResults: TStrings
Membership in the list or alias.
Expand is a procedure used to determine if the argument in AUsername is a valid mailing list or mailbox alias on the server, and retrieve the email addresses for the membership of that list in AResults. Expand uses the SMTP EXPN command to retrieve the results, with one name and email address per line.

The following is an example of successful result values that might be returned in AResults when using Expand with the Username 'Example-People':

    Jon Postel 
    Fred Fonebone 
    Sam Q. Smith 
    Quincy Smith <@USC-ISIF.ARPA:Q-Smith@ISI-VAXA.ARPA>

Use Verify to validate an individual name or address on the SMTP server.

Sends a message without an Indy message instance.
class procedure QuickSend(const AHost: String; const ASubject: String; const ATo: String; const AFrom: String; const AText: String);
const AHost: String
SMTP server used to send the message.
const ASubject: String
Subject of the message.
const ATo: String
Recipient(s) of the message.
const AFrom: String
Person sending the message.
const AText: String
Body text for the message.
QuickSend is a class procedure that allows the SMTP client to quickly send a message without the need for a TIdMessage instance. QuickSend cannot be used to send messages with attachments. Use Send to transfer messages that include attachments.

Parameters for the method are used to construct a TIdMessage instance, connect and send the message to the SMTP server, and to Disconnect from the SMTP server. The following is an example of using QuickSend with pre-defined application variables:

    ASmtp.QuickSend(SMailhost, SSubject, SUserAccount,
      SContactAccount, ABody.Text);
  except on E:
    do DoReminderTransmitError(E);

Sends an Indy message instance to the SMTP server.
procedure Send(AMsg: TIdMessage); virtual;
AMsg: TIdMessage
Message instance to be transmitted.
Send is a procedure that sends the TIdMessage specified in AMsg using the SMTP server specified in the Host property. Send will reset the SMTP session, and call Authenticate when the SMTP session has never been authenticated.

Send transmits RFC 822 message headers to the SMTP server, including From, Recipients, Carbon-Copy recipients, and Blind Carbon-Copy recipients before sending the data and extra RFC 822 message headers for the message. Send inserts the value in MailAgent header as the first values in the data for the message. Send terminates transfer of data to the SMTP server using the '.' end-of-transmission marker.

TIdSMTP, See Also
Verifies that an alias or name is a user mailbox on the SMTP server.
function Verify(AUserName: String): String; virtual;
AUserName: String
Value to be verified.
Return Value
String - Fully qualified User name and email address.
Verify is a String function used to verify that the User specified in AUsername is a valid address on the SMTP server. Verify returns the fully sepecified User name and email address on success. Use Expand to determine the membership in a mailing list.

The following is an example of the value returned from a successful Verify command request using 'Smith' in AUsername:

    Fred Smith 

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