IMAP: Initiate the connection (including protected modes)
To connect to an IMAP server you need to create an instance of TElIMAPClient 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. SSLMode property of the IMAP client will define, in which mode (implicit or explicit) SSL/TLS is used (see property description for details). If Implicit mode is chosen for SSL/TLS, you usually need to set Port property to 993. In Explicit mode the default port 143 is used most often.
After the connection is opened, you need to login with a username and password.
If a connection attempt has been made (no matter successful or not), you need to close the connection.
TElIMAPClient client = new TElIMAPClient(); client.OnCertificateValidate += new SBSSLCommon.TSBCertificateValidateEvent(client_OnCertificateValidate); client.Address = "imap.gmail.com"; client.Port = 993; client.UseSSL = true; client.SSLMode = TSBSSLMode.smImplicit; // TSBSSLMode.smExplicit client.Open();
Client := TElIMAPClient.Create(nil); Client.OnCertificateValidate := OnCertificateValidate; Client.Address := 'imap.gmail.com'; Client.Port := 993; Client.UseSSL := True; Client.SSLMode := smImplicit; //smExplicit Client.Open;