SmtpClient.BeginTestRecipients Method

Tests email address asynchronously.

[Visual Basic]
Public Function BeginTestRecipients( _
    server As SmtpServer, _
    mail As SmtpMail, _
    callback As AsyncCallback, _
    state As Object _
) As SmtpClientAsyncResult
public SmtpClientAsyncResult BeginTestRecipients(
    SmtpServer server,
    SmtpMail mail,
    AsyncCallback callback,
    Object state
public: SmtpClientAsyncResult^ BeginTestRecipients(
    SmtpServer^ server,
    SmtpMail^ mail,
    AsyncCallback^ callback,
    Object^ state
public function BeginTestRecipients( 
    server : SmtpServer, 
    mail : SmtpMail, 
    callback : AsyncCallback, 
    state As Object 
) : SmtpClientAsyncResult;


A SmtpServer instances used to test recipients.
A SmtpMail instance to test.
The AsyncCallback delegate.
An object containing state information for this request.

Return Value

An SmtpClientAsyncResult that references the asynchronous send.


How does it work? Firstly, SmtpClient performs a DNS MX record query. If it retrieves the recipient's local SMTP server successfully, SmtpClient will try to connect to this server. SmtpClient then performs "RCPT TO" command to test if this SMTP server accept this email address. 

Please always pass null (Nothing in Visual Basic) to SmtpServer paramter except you want to test whether an email address will be accepted by a specified SMTP server.


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

[VB - Test Email Address]

Imports EASendMail

Sub TestEmailAddress()

    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    oMail.From = New MailAddress("")
    oMail.To.Add(New MailAddress(""))

    Dim oSmtp As SmtpClient = New SmtpClient
    Dim asyncResult As SmtpClientAsyncResult = oSmtp.BeginTestRecipients(Nothing, oMail, Nothing, Nothing)
    Do While Not asyncResult.AsyncWaitHandle.WaitOne(5, False)
        ' do other thing


Catch exp As Exception
    Console.WriteLine("Exception: {0}", exp.Message)
End Try

End Sub

[C# - Test Email Address] using System; using EASendMail; void TestEmailAddress() { try { SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = new MailAddress(""); oMail.To.Add(new MailAddress("")); SmtpClient oSmtp = new SmtpClient(); SmtpClientAsyncResult asyncResult = oSmtp.BeginTestRecipients(null, oMail, null, null); while (!asyncResult.AsyncWaitHandle.WaitOne(5, false)) { // do other thing } oSmtp.EndTestRecipients(asyncResult); Console.WriteLine("PASS"); } catch (Exception exp) { Console.WriteLine("Exception: {0}", exp.Message); } }
[C++/CLI - Test Email Address] using namespace System; using namespace EASendMail; void TestEmailAddress() { try { SmtpMail ^oMail = gcnew SmtpMail("TryIt"); oMail->From = gcnew MailAddress(""); oMail->To->Add(gcnew MailAddress("")); SmtpClient ^oSmtp = gcnew SmtpClient(); SmtpClientAsyncResult ^ar = oSmtp->BeginTestRecipients(nullptr, oMail, nullptr, nullptr); while (!ar->AsyncWaitHandle->WaitOne(5, false)) { // do other thing; } oSmtp->EndTestRecipients(ar); Console::WriteLine("PASS"); } catch (Exception ^exp) { Console::WriteLine("Exception: {0}", exp->Message); } }

Test Email Address

See Also

Bulk Email Sender Guidelines
Process Bounced Email (Non-Delivery Report) and Email Tracking