Begins an asynchronous request for authenticating the user on the SMTP server.
An IAsyncResult that references the asynchronous authentication.
This method is an asynchronous version of Login.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidStateException | There is already an operation in progress. |
This WinForms sample demonstrates using asynchronous authentication in conjunction with a callback function.
[C#] // To use the code below, import MailBee namespaces at the top of your code. using MailBee; using MailBee.SmtpMail; // Put the code below inside your class. // Login callback function. private void LoginCallback(IAsyncResult result) { Smtp mailer = (Smtp)result.AsyncState; mailer.EndLogin(); MessageBox.Show("Authentication succeeded"); // Close the connection. mailer.Disconnect(); } // The actual code. private void Form1_Load(object sender, System.EventArgs e) { Smtp mailer = new Smtp(); mailer.SmtpServers.Add("smtp.somehost.com", "jdoe", "secret"); // Connect to SMTP server and say Hello. mailer.Connect(); mailer.Hello(); // Initiate an asynchronous authentication attempt. mailer.BeginLogin(new AsyncCallback(LoginCallback), mailer); }
[Visual Basic] ' To use the code below, import MailBee namespaces at the top of your code. Imports MailBee Imports MailBee.SmtpMail ' Put the code below inside your class. ' Login callback function. Private Sub LoginCallback(ByVal result As IAsyncResult) Dim mailer As Smtp = result.AsyncState mailer.EndLogin() MsgBox("Authentication succeeded") ' Close the connection. mailer.Disconnect() End Sub ' The actual code. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim mailer As New Smtp mailer.SmtpServers.Add("smtp.somehost.com", "jdoe", "secret") ' Connect to SMTP server and say Hello. mailer.Connect() mailer.Hello() ' Initiate an asynchronous authentication attempt. mailer.BeginLogin(New AsyncCallback(AddressOf LoginCallback), mailer) End Sub
Smtp Class | MailBee.SmtpMail Namespace | Login