SMTP: Initiate the connection (including protected modes)
To connect to an SMTP server you need to create an instance of TElSMTPClient class and setup the needed connection-related properties, such as Address and, optionally, Port. If SSL/TLS protection is used, you need to set UseSSL property to true, and also it's required to create an event handler for OnCertificateValidate event in order to validate certificates of the server. Before enabling TLS you need to setup TLS-specific properties and events as described in the corresponding how-to article.
It's highly recommended to use SSL/TLS to secure SMTP protocol flow as in several authentication schemes it sends login credentials in plain text. SSLMode property of the POP3 client will define, in which mode (implicit or explicit) SSL/TLS is used (see property description for details).
In Implicit SSL mode, the SSL session is established before any SMTP command is sent. In Explicit mode, the SSL session is automatically established before the login credentials are sent. There is also the explicit manual mode available. In this mode the developer is responsible for call of EstablishSSL() method at the appropriate time.
SMTP protocol uses port 25 for insecure connection, port 587 for secure connection in explicit mode, and port 465 for secure connection in implicit mode.
If a connection attempt has been made (no matter successful or not), you need to close the connection.
After the successful connection to the server your code needs to login to the server, before it can send messages.
TElSMTPClient smtp = new TElSMTPClient(); smtp.Address = "smtp.gmail.com"; smtp.Port = 587; // setup SSL parameters smtp.SSLMode = TSBSSLMode.smExplicit; smtp.UseSSL = true; smtp.OnCertificateValidate += new TSBCertificateValidateEvent(...); // open a connection smtp.Open(); //login and send mail messages to the server