ImapBeginStartTls Method |
Note: This API is now obsolete.
Namespace: MailBee.ImapMail
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use StartTlsAsync instead.")] public IAsyncResult BeginStartTls( AsyncCallback callback, Object state )
Exception | Condition |
---|---|
MailBeeInvalidStateException | There is already an operation in progress. |
// To use the code below, import MailBee namespaces at the top of your code. using MailBee; using MailBee.ImapMail; // Put the code below inside your class. // TlsStarted event handler. private void OnTlsStarted(object sender, TlsStartedEventArgs e) { MessageBox.Show("TLS/SSL negotiation complete. Secure connection is ready."); } // The actual code. private void Form1_Load(object sender, System.EventArgs e) { Imap imp = new Imap(); // Let MailBee process events. imp.RaiseEventsViaMessageLoop = false; imp.TlsStarted += new TlsStartedEventHandler(OnTlsStarted); imp.Connect("mail.company.com"); // Initiate an asynchronous TLS/SSL negotiation. imp.BeginStartTls(null, null); // Simulate some lengthy work here... for (int i = 0; i < 100; i++) { // Make a portion of the work. System.Threading.Thread.Sleep(10); // Process events which were raised during execution of the work above. imp.Wait(0); } // If the connection was not established during execution of the lengthy // work, wait until it's established. imp.Wait(); // End the connection request. imp.EndStartTls(); // The connection is now under TLS/SSL layer! // Disconnect from the server. imp.Disconnect(); }