Begins an asynchronous request for a connecting to an SMTP server.
An IAsyncResult that references the asynchronous POP-before-SMTP authentication.
This method is an asynchronous version of Connect.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidStateException | There is already an operation in progress. |
This console sample connects to the SMTP server asynchronously and handles Connected event. No callback function is used.
[C#] using System; using MailBee; using MailBee.SmtpMail; class Sample { // "Connected" event handler. private static void OnConnected(object sender, ConnectedEventArgs e) { Console.WriteLine("Successfully connected to the server."); } // The actual code. static void Main(string[] args) { Smtp mailer = new Smtp(); mailer.SmtpServers.Add("smtp.somehost.com"); // Subscribe to the Connected event. mailer.Connected += new ConnectedEventHandler(OnConnected); // Initiate an asynchronous connection. mailer.BeginConnect(null, null); // Simulate some lengthy work here. At the same time, // the connection with the server is established on another thread. System.Threading.Thread.Sleep(3000); // End the connection request. mailer.EndConnect(); mailer.Disconnect(); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.SmtpMail Class Sample ' "Connected" event handler. Private Shared Sub OnConnected(ByVal sender As Object, ByVal e As ConnectedEventArgs) Console.WriteLine("Successfully connected to the server.") End Sub ' The actual code. Shared Sub Main(ByVal args As String()) Dim mailer As New Smtp mailer.SmtpServers.Add("smtp.somehost.com") ' Subscribe to the Connected event. AddHandler mailer.Connected, AddressOf OnConnected ' Initiate an asynchronous connection. mailer.BeginConnect(Nothing, Nothing) ' Simulate some lengthy work here. At the same time, ' the connection with the server is established on another thread. System.Threading.Thread.Sleep(3000) ' End the connection request. mailer.EndConnect() mailer.Disconnect() End Sub End Class
Smtp Class | MailBee.SmtpMail Namespace | Connect