Tests an e-mail address.
[Visual Basic] Public Sub TestRecipients( _ server As SmtpServer, _ mail As SmtpMail _ )
[C#] public void TestRecipients( SmtpServer server, SmtpMail mail );
[C++] public: void TestRecipients( SmtpServer^ server, SmtpMail^ mail );
[JScript] public function TestRecipients( server : SmtpServer, mail : SmtpMail );
Parameters
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 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 oSmtp.TestRecipients(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; 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(); oSmtp.TestRecipients(null, oMail); 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("from@adminsystem.com"); oMail->To->Add(gcnew MailAddress("to@adminsystem.com")); SmtpClient ^oSmtp = gcnew SmtpClient(); oSmtp->TestRecipients(nullptr, oMail); Console::WriteLine("PASS"); } catch (Exception ^exp) { Console::WriteLine("Exception: {0}", exp->Message); } }
Test Email Address
Validate Email Address Syntax and Test Email Address in VB
Validate Email Address Syntax and Test Email Address in C#
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 accepts this email address.
Because it totally depends on your networking connection, if your networking connection to the recipient server is bad or your IP address is blocked by the recipient server, test will be failed, but it doesn't mean this email address is invalid.
Moreover, to prevent email address testing, many email providers accept the recipient address at first no matter if the address is valid or invalid, only after you sent the email data to the server, then the server rejects it if the recipient address is invalid.
Send the email to the recipient without testing. If you don't get Transport Error and Failure Report in 24 hours, that means the recipient is valid. If you get Failure Report, you should consider to remove this recipient from your mail listing.
See Also
Bulk Email Sender Guidelines
Process Bounced Email (Non-Delivery Report) and Email Tracking