pgscannell
  • pgscannell
  • 50.75% (Neutral)
  • Newbie Topic Starter
5 years ago
Here is my function:

Public Function Verify_EmailAddress ( strEmailAddress As String ) As String
Dim strReturn As String = ""

Try
Dim oMail As New EASendMail.SmtpMail ( "TryIt" )
Dim oServer As New EASendMail.SmtpServer ("" ) ' Do not set SMTP server address
Dim oSmtp As New EASendMail.SmtpClient ()

oSmtp.LogFileName = "C:\smtp.txt"
Dim mFrom As EASendMail.MailAddress = New EASendMail.MailAddress ( "PaulGScannell@gmail.com", "Jerry" )
'Dim mTo As EASendMail.MailAddressCollection = New EASendMail.MailAddressCollection ( strEmailAddress, "TestValidation" )

oMail.From = mFrom
oMail.To = strEmailAddress

oSmtp.TestRecipients(oServer, oMail)

Catch ep As Exception
strReturn = ep.Message
End Try

Return strReturn
End Function
ivan
  • ivan
  • 100% (Exalted)
  • Administration
5 years ago


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 accepts this email address.

Why we don't recommend testing 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.

Recommended Solution

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.

Please do not use SmtpServer("") to send email, because if you don't have a static IP address and set correct SPF record, almost email providers would reject your message due to anti-spam policy.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.