| Visual Basic (Declaration) | |
|---|---|
Public Overloads Function BeginSend( _ ByVal toAddress As String, _ ByVal fromAddress As String, _ ByVal subject As String, _ ByVal body As String, _ ByVal state As Object _ ) As IAsyncResult | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Smtp Dim toAddress As String Dim fromAddress As String Dim subject As String Dim body As String Dim state As Object Dim value As IAsyncResult value = instance.BeginSend(toAddress, fromAddress, subject, body, state) | |
| C# | |
|---|---|
public IAsyncResult BeginSend( string toAddress, string fromAddress, string subject, string body, object state ) | |
| Managed Extensions for C++ | |
|---|---|
public: IAsyncResult* BeginSend( string* toAddress, string* fromAddress, string* subject, string* body, Object* state ) | |
| C++/CLI | |
|---|---|
public: IAsyncResult^ BeginSend( String^ toAddress, String^ fromAddress, String^ subject, String^ body, Object^ state ) | |
Parameters
- toAddress
- Recipient of the email.
- fromAddress
- Sender of the email.
- subject
- Subject of the email.
- body
- Bodytext of the email.
- state
- User state information.
Return Value
An IAsyncResult that represents the asynchronous operation, which could still be pending.| Exception | Description |
|---|---|
| Dart.PowerTCP.Mail.ProtocolException | Bad SMTP protocol response received from server. |
| System.InvalidOperationException | Smtp.BeginSend used without providing an EndSend event handler. |
| System.Net.Sockets.SocketException | The requested address is not valid in its context. |
| System.IO.IOException | The filename, directory name, or volume label syntax is incorrect. |
| System.ArgumentException | A required argument contains invalid characters, is empty, or contains only white spaces. |
| Visual Basic | Copy Code |
|---|---|
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Mail" ' at the top of your class. Private Sub BeginSendTest() ' Begin to asynchronously send a message Smtp1.Server = "mail.test.com" Smtp1.BeginSend("you@test.com", "me@test.com", "test", "test message", Nothing) End Sub Private Sub Smtp1_EndSend(ByVal sender As Object, ByVal e As Dart.PowerTCP.Mail.SmtpEventArgs) Handles Smtp1.EndSend ' Send operation complete. Check to see if an exception was thrown during the operation. If e.Exception Is Nothing Then Debug.WriteLine("Send operation complete") Dim m As MailAddress For Each m In e.Response.Recipients Debug.WriteLine("Mail sent to " + m.Address) Next End If End Sub | |
| C# | Copy Code |
|---|---|
// Be sure to import the namespace by putting "using Dart.PowerTCP.Mail;" // at the top of your class. private void BeginSendTest() { // Begin to asynchronously send a message smtp1.Server = "mail.test.com"; smtp1.BeginSend("you@test.com", "me@test.com", "test", "test message", null); } private void smtp1_EndSend(object sender, Dart.PowerTCP.Mail.SmtpEventArgs e) { // Send operation complete. Check to see if an exception was thrown during the operation. if(e.Exception == null) { Debug.WriteLine("Send operation complete"); foreach(MailAddress m in e.Response.Recipients) Debug.WriteLine("Mail sent to " + m.Address); } } | |
This method begins to send a basic text email. Upon completion the Smtp.EndSend event will be raised. An SmtpEventArgs object will be passed into this event, containing data about the message sent. For example, the SmtpEventArgs will contain data such as the length of the email message sent. If you are using the Smtp component as a reference, you must "wire up" the event yourself. This involves creating a method that acts as the event handler that implements the SmtpEventHandler delegate. See Using Events When Using A Component As A Reference for more information.
The object state is useful for any kind of state information that you would like accessible in the Smtp.EndGet event. Since the method is "disconnected" from the calling code and returns to the calling thread elsewhere, you may wish to pass an object/variable as state to be retrieved and used in the event handler.
To send a basic text email synchronously, use Smtp.Send.
Use this method if you wish to send a basic text email message transparently with minimal application impact, as execution occurs on another thread.
Target Platforms: Microsoft .NET Framework 2.0