PowerTCP Mail for .NET
EndSend Event
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Smtp Class : EndSend Event




Raised when the Smtp.BeginSend request completes.

Syntax

Visual Basic (Declaration) 
<CategoryAttribute("Completion")>
<DescriptionAttribute("Raised when the BeginSend() request completes.")>
Public Event EndSend As SendEventHandler
Visual Basic (Usage)Copy Code
Dim instance As Smtp
Dim handler As SendEventHandler
 
AddHandler instance.EndSend, handler
C# 
[CategoryAttribute("Completion")]
[DescriptionAttribute("Raised when the BeginSend() request completes.")]
public event SendEventHandler EndSend
Managed Extensions for C++ 
[CategoryAttribute("Completion")]
[DescriptionAttribute("Raised when the BeginSend() request completes.")]
public: __event SendEventHandler* EndSend
C++/CLI 
[CategoryAttribute("Completion")]
[DescriptionAttribute("Raised when the BeginSend() request completes.")]
public:
event SendEventHandler^ EndSend

Event Data

The event handler receives an argument of type SmtpEventArgs containing data related to this event. The following SmtpEventArgs properties provide information specific to this event.

PropertyDescription
Exception Gets any exception which occurred during the asynchronous operation.
Response Gets the SmtpResult object, encapsulating data about the message sent.
State Gets the object that was included as part of the associated method call.

Example

The following example demonstrates using the Smtp.BeginSend method and the Smtp.EndSend event.
Visual BasicCopy 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);
    }
}

Remarks

This event is raised when the asynchronous method call Smtp.BeginSend completes. An SmtpEventArgs object will be passed into the event, containing information about the sent email message.

If any errors occurred during the asynchronous operation, they would be returned in the SmtpEventArgs object, check SmtpEventArgs.Exception to check for any exception.

For more information on using events using PowerTCP.NET within the Visual Studio.NET environment, see Using Events Within The Visual Studio.NET Environment.

If you are using the Smtp component as a reference, you must create a method to handle the event yourself. To learn how to do this, see Using Events When The A Component Is Used As A Reference.

This event MUST be implemented if you are using the Smtp.BeginSend method. See Using EndXXX Events for more information.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.