Begins an asynchronous request for sending the specified user-defined command to the server and getting the response.
An IAsyncResult that references the asynchronous user-defined command execution.
This method is an asynchronous version of ExecuteCustomCommand.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidStateException | There is already an operation in progress. |
Sending a mail message to the POP3 server in WinForms application (the POP3 server must support XTND XMIT extension). Sending itself is performed in a few stages:
[C#] // To use the code below, import MailBee namespaces at the top of your code. using MailBee; using MailBee.Pop3Mail; using MailBee.Mime; // Put the code below inside your class. // XTND XMIT callback function. private void XtndXmitCallback(IAsyncResult result) { Pop3 pop = (Pop3)result.AsyncState; // Process the results of XTND XMIT command. try { pop.EndExecuteCustomCommand(); } catch (MailBeePop3NegativeResponseException) { MessageBox.Show("XTND XMIT command is not supported. The server responded: " + pop.GetServerResponse()); pop.Disconnect(); return; } // Create a mail message to be sent. MailMessage msg = new MailMessage(); msg.From.Email = "jdoe@mydomain.com"; msg.To.AsString = "kathy@herdomain.com"; msg.Subject = "Meeting request"; msg.BodyPlainText = "Hi, Kathy,\r\nCan we meet tomorrow?\r\n\r\nRegards,\r\nJohn"; // Encode the mail message source as multi-line POP3 request. string messageSource = System.Text.Encoding.Default.GetString(msg.GetMessageRawData()); messageSource = messageSource.Replace("\r\n.", "\r\n.."); // Send the mail message asynchronously. pop.BeginExecuteCustomCommand(messageSource + "\r\n.\r\n", false, new AsyncCallback(SubmissionCallback), pop); } // Mail message submission callback function. private void SubmissionCallback(IAsyncResult result) { Pop3 pop = (Pop3)result.AsyncState; // Process the results of the mail message submission. try { pop.EndExecuteCustomCommand(); MessageBox.Show("Message submitted for delivery"); } catch (MailBeePop3NegativeResponseException) { MessageBox.Show("Message was not submitted. The server responded: " + pop.GetServerResponse()); } pop.Disconnect(); } // The actual code. private void Form1_Load(object sender, System.EventArgs e) { Pop3 pop = new Pop3(); pop.Connect("pop.mydomain.com"); pop.Login("jdoe", "secret"); // Issue XTND XMIT command asynchronously. pop.BeginExecuteCustomCommand("XTND XMIT\r\n", false, new AsyncCallback(XtndXmitCallback), pop); }
[Visual Basic] ' To use the code below, import MailBee namespaces at the top of your code. Imports MailBee Imports MailBee.Pop3Mail Imports MailBee.Mime ' Put the code below inside your class. ' XTND XMIT callback function. Private Sub XtndXmitCallback(ByVal result As IAsyncResult) Dim pop As New Pop3 pop = result.AsyncState ' Process the results of XTND XMIT command. Try pop.EndExecuteCustomCommand() Catch MailBeePop3NegativeResponseException As Exception MsgBox("XTND XMIT command is not supported. The server responded: " & _ pop.GetServerResponse()) pop.Disconnect() Return End Try ' Create a mail message to be sent. Dim msg As New MailMessage msg.From.Email = "jdoe@mydomain.com" msg.To.AsString = "kathy@herdomain.com" msg.Subject = "Meeting request" msg.BodyPlainText = "Hi, Kathy,\r\nCan we meet tomorrow?\r\n\r\nRegards,\r\nJohn" ' Encode the mail message source as multi-line POP3 request. Dim messageSource As String = System.Text.Encoding.Default.GetString(msg.GetMessageRawData()) messageSource = messageSource.Replace("\r\n.", "\r\n..") ' Send the mail message asynchronously. pop.BeginExecuteCustomCommand(messageSource + "\r\n.\r\n", False, _ New AsyncCallback(AddressOf SubmissionCallback), pop) End Sub ' Mail message submission callback function. Private Sub SubmissionCallback(ByVal result As IAsyncResult) Dim pop As New Pop3 pop = result.AsyncState ' Process the results of the mail message submission. Try pop.EndExecuteCustomCommand() MsgBox("Message submitted for delivery") Catch MailBeePop3NegativeResponseException As Exception MsgBox("Message was not submitted. The server responded: " & _ pop.GetServerResponse()) End Try pop.Disconnect() End Sub ' The actual code. Private Sub Form11_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim pop As New Pop3 pop.Connect("pop.mydomain.com") pop.Login("jdoe", "secret") ' Issue XTND XMIT command asynchronously. pop.BeginExecuteCustomCommand("XTND XMIT\r\n", False, _ New AsyncCallback(AddressOf XtndXmitCallback), pop) End Sub
Pop3 Class | MailBee.Pop3Mail Namespace | ExecuteCustomCommand