Occurs when the connection with the server becomes secure.
The event handler receives an argument of type TlsStartedEventArgs containing data related to this event. The following TlsStartedEventArgs properties provide information specific to this event.
| Property | Description |
|---|---|
| Protocol | Gets application-level protocol of the current connection. |
| RemoteEndPoint | Gets a reference to the end point of the server host. |
| RemoteHostName | Gets the host name of the server. |
| State | Gets a reference to the object which was supplied by the developer in state parameter of asynchronous methods of the mailer components. |
This event is raised when TLS/SSL negotiation completes and TLS session successfully starts. Usually, this happens as a result of successful completion of StartTls method or if automatic TLS/SSL negotiation was requested via setting SslMode property to non-Manual value.
This console sample demonstrates that TlsStarted event is raised during executing Login method when SslMode property is set to UseStartTls value.
[C#] using System; using MailBee; using MailBee.ImapMail; using MailBee.Security; class Sample { // TlsStarted event handler. private static void OnTlsStarted(object sender, TlsStartedEventArgs e) { // This will happen during Login method execution. Console.WriteLine("TLS/SSL session started."); } // The actual code. static void Main(string[] args) { Imap imp = new Imap(); // Subscribe to TlsStarted event. imp.TlsStarted += new TlsStartedEventHandler(OnTlsStarted); // Notify MailBee it should start TLS/SSL session when appropriate. // The connection is made to the regular port so that STARTTLS command // will be used to start TLS/SSL session. imp.SslMode = SslStartupMode.UseStartTls; imp.Connect("imap.company.com"); Console.WriteLine("Connected to the server. Will login now..."); // TLS/SSL negotiation will take place here. Thus, user credentials // will be sent to the mail server already under secure TLS/SSL layer. imp.Login("jdoe", "secret"); Console.WriteLine("Logged in successfully."); imp.Disconnect(); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.ImapMail Imports MailBee.Security Module Sample ' TlsStarted event handler. Private Sub OnTlsStarted(ByVal sender As Object, ByVal e As TlsStartedEventArgs) ' This will happen during Login method execution. Console.WriteLine("TLS/SSL session started.") End Sub ' The actual code. Sub Main(ByVal args As String()) Dim imp As New Imap ' Subscribe to TlsStarted event. AddHandler imp.TlsStarted, AddressOf OnTlsStarted ' Notify MailBee it should start TLS/SSL session when appropriate. ' The connection is made to the regular port so that STARTTLS command ' will be used to start TLS/SSL session. imp.SslMode = SslStartupMode.UseStartTls imp.Connect("imap.company.com") Console.WriteLine("Connected to the server. Will login now...") ' TLS/SSL negotiation will take place here. Thus, user credentials ' will be sent to the mail server already under secure TLS/SSL layer. imp.Login("jdoe", "secret") Console.WriteLine("Logged in successfully.") imp.Disconnect() End Sub End Module
Imap Class | MailBee.ImapMail Namespace | SslMode | StartTls