PDA

View Full Version : Can VBA help validate an email address



stanl
09-07-2007, 10:06 AM
First off: this is not intended to elicit help to SPAM people. have a friend who has been quite generous with his frequent flyer miles (so our daughter can visiti us) in exchange for scripting help. Anyway, he needs help with validating bulk emails he wants to send with links to his site, but to a select group of emails that have logged into his site for information.

My script accepts an input file of ~1400 addresses and first of all runs a ping against the Domain. However domains like aol.com will timeout [they have issues] even though the email is valid, and other valid domains will return a Mailer Deamon.....:banghead:

I would like to get to sending 'HELO' to the full email [not just the domain] and eliminate those also. Can this be done?:dunno

The point is my friend does not want to be intrusive [read: separate the wheat from the chaff]...Stan

Zack Barresse
09-16-2007, 03:07 PM
Hi Stan,

Sure. You can use a UDF...

Sub TestMe()
Dim strAddy As String
strAddy = "test.this@domain.com"
MsgBox strAddy & ": " & IsValidEmail(strAddy), vbExclamation, "TEST"
End Sub

Private Function IsValidEmail(value As String) As Boolean
'Originally from Tommy Gun
Dim RE As Object
Set RE = CreateObject("vbscript.RegExp")
RE.Pattern = "^[a-zA-Z0-9\._-]+@([a-zA-Z0-9_-]+\.)+([a-zA-Z]{2,3})$"
IsValidEmail = RE.Test(value)
Set RE = Nothing
End Function

I nabbed this originally from Tommy Gun over at MrExcel. Pretty useful little bit. I only added his name to credit it.

HTH

daniel_d_n_r
09-21-2007, 05:07 PM
that is sweet I have never seen Regular expressions in VBA or the VBA help file.