SmtpClient.TestRecipientsAsync Method


Tests an e-mail address asynchronously (async, await).

[Visual Basic]
Public Function TestRecipientsAsync( _
    server As SmtpServer, _
    mail As SmtpMail _
) As Task
[C#]
public Task TestRecipientsAsync(
    SmtpServer server,
    SmtpMail mail
);
[C++]
public: Task^ TestRecipientsAsync(
    SmtpServer^ server,
    SmtpMail^ mail
);
[JScript]
public function TestRecipientsAsync( 
    server : SmtpServer, 
    mail : SmtpMail
): Task;

Parameters

server
A SmtpServer instances used to test.
mail
A SmtpMail instance to test.

Remarks

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.

Example

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

[VB - Test Email Address]

Imports EASendMail

Async Sub TestEmailAddress()

Try
    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    oMail.From = New MailAddress("from@adminsystem.com")
    oMail.To.Add(New MailAddress("to@adminsystem.com"))

    Dim oSmtp As SmtpClient = New SmtpClient

    Await oSmtp.TestRecipientsAsync(Nothing, oMail)

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

End Sub


[C# - Test Email Address] using System; using EASendMail; async void TestEmailAddress() { try { SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = new MailAddress("from@adminsystem.com"); oMail.To.Add(new MailAddress("to@adminsystem.com")); SmtpClient oSmtp = new SmtpClient(); await oSmtp.TestRecipientsAsync(null, oMail); 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