SmtpClientAsyncResult Class


Provides an implementation of System.IAsyncResult for use by BeginSendMail method and BeginTestRecipients method to implement the standard asynchronous method pattern.

System.Object
    EASendMail.SmtpClientAsyncResult

[Visual Basic]
Public Class SmtpClientAsyncResult
    Implements IAsyncResult
[C#]
public class SmtpClientAsyncResult : IAsyncResult
[C++]
public ref class SmtpClientAsyncResult : public IAsyncResult
[JScript]
public class SmtpClientAsyncResult implements IAsyncResult

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Methods and Properties

Please refer to .NET Framework SDK System.IAsyncResult interface.

Example

[Visual Basic, C#, C++] To get the full samples of EASendMail, please refer to Samples section.

[VB - Send Email Asynchronously]

Imports EASendMail

Sub SendMail()

    Try
        Dim oMail As SmtpMail = New SmtpMail("TryIt")

        oMail.From = New MailAddress("from@adminsystem.com")
        oMail.To.Add(New MailAddress("to@adminsystem.com"))

        oMail.Subject = "test subject"
        oMail.TextBody = "test body"

        Dim oServer As SmtpServer = New SmtpServer("myserveraddress")
        ' SMTP user authentication
        oServer.User = "myusername"
        oServer.Password = "mypassword"

        ' Most mordern SMTP servers require SSL/TLS connection now.
        ' ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
        oServer.ConnectType = SmtpConnectType.ConnectTryTLS

        Dim oSmtp As SmtpClient = New SmtpClient()
        Dim asyncResult As SmtpClientAsyncResult = oSmtp.BeginSendMail(oServer, oMail, Nothing, Nothing)
        Do While Not asyncResult.AsyncWaitHandle.WaitOne(5, False)
            ' do something
        Loop

        oSmtp.EndSendMail(asyncResult)
        Console.WriteLine("This message has been submitted to server successfully!")
    Catch exp As Exception
        Console.WriteLine("Exception: {0}", exp.Message)
    End Try

End Sub


[C# - Send Email Asynchronously] using System; using EASendMail; void SendMail() { try { SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = new MailAddress("from@adminsystem.com"); oMail.To.Add(new MailAddress("to@adminsystem.com")); oMail.Subject = "test subject"; oMail.TextBody = "test body"; SmtpServer oServer = new SmtpServer("myserveraddress"); // SMTP user authentication oServer.User = "myusername"; oServer.Password = "mypassword"; // Most mordern SMTP servers require SSL/TLS connection now. // ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically. oServer.ConnectType = SmtpConnectType.ConnectTryTLS; SmtpClient oSmtp = new SmtpClient(); SmtpClientAsyncResult asyncResult = oSmtp.BeginSendMail(oServer, oMail, null, null); while (!asyncResult.AsyncWaitHandle.WaitOne(5, false)) { // do something } oSmtp.EndSendMail(asyncResult); Console.WriteLine("the message was sent to {0} successfully", asyncResult.SmtpClientInstance.CurrentSmtpServer.Server); } catch (Exception exp) { Console.WriteLine("Exception: {0}", exp.Message); } }
[C++/CLI - Send Email Asynchronously] using namespace System; using namespace EASendMail; void SendMail() { try { SmtpMail ^oMail = gcnew SmtpMail("TryIt"); oMail->From = gcnew MailAddress("from@adminsystem.com"); oMail->To->Add(gcnew MailAddress("to@adminsystem.com")); oMail->Subject = "test subject"; oMail->TextBody = "test body"; SmtpServer ^oServer = gcnew SmtpServer("myserveraddres"); // SMTP user authentication oServer->User = "myusername"; oServer->Password = "mypassword"; // Most mordern SMTP servers require SSL/TLS connection now. // ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically. oServer->ConnectType = SmtpConnectType::ConnectTryTLS; SmtpClient ^oSmtp = gcnew SmtpClient(); SmtpClientAsyncResult^ asyncResult = oSmtp->BeginSendMail(oServer, oMail, nullptr, nullptr); while (!asyncResult->AsyncWaitHandle->WaitOne(5, false)) { // do other thing; } oSmtp->EndSendMail(asyncResult); Console::WriteLine("the message was sent to {0} successfully", asyncResult->SmtpClientInstance->CurrentSmtpServer->Server); } catch (Exception ^exp) { Console::WriteLine("Exception: {0}", exp->Message); } }

See Also

SmtpClient.BeginSendMail Method
SmtpClient.BeginSendRawMail Method
Work with EASendMail Service (Email Queuing)
SmtpClient.SendMailToQueue Method
SmtpClient.SendMailToQueueEx Method

Online Tutorials

Send Email in VB 6.0 - Tutorial
Send Email in C# - Tutorial
Send Email in VB.NET - Tutorial
Send Email in Visual C++ - Tutorial
Send Email in Managed C++/CLI - Tutorial
Send Email in Delphi - Tutorial
Send Email in MS SQL stored procedure - Tutorial