Regular expression email filtering

Get help on programming - C++, Java, Delphi, etc.
Post Reply
SykomantiS
Registered User
Posts: 14085
Joined: 06 Oct 2004, 02:00
Location: Location, Location...
Contact:

Regular expression email filtering

Post by SykomantiS »

Hi all.

So yesterday while mass mailing our students, one or more emails failed and consequently threw an unhandled exception in our application. before sending any mails however, the list of emails pulled from the db are checked for validity using the following regular expression: (vb code, VS2008)

Code: Select all

If Regex.Match(email, "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*").Success Then
Return True
Else
Return False
End If
Now, as stated, one of the email addies passed this test, but still threw an error. Now I've physically gone over the list and couldn't find the offending address (granted, it's a long list and I could have missed something). The problem is, I don't have a screenshot of the error, and to reproduce it would mean to physically resend all the hundreds of mails, in effect spamming our students. :? So all I can do is try and find the offending email address.

I'm not really good with regex and to be brutally honest, I didn't build the above expression, nor do I even completely understand it. (We don't use regular expressions all that much) Which is why I'm posting this here. Can anyone find fault with the expression used? Would it allow an address that would fail when sending?

The other thing that bugs me is that we are using vb with its inbuilt system.net.mail, and I'm unsure if this will throw an exception when, for instance, an address is valid, but spelt incorrectly. If this is the case then I well, **** :? (Also, then we probably would get more than one error, which we don't).

Right now I'm only concerned with allowing valid emails. I'll worry about incorrect spelling later.

Any help?
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: Regular expression email filtering

Post by Bladerunner »

So take that part of the code and the list of emails. Write a small application that goes through the process of sending emails but instead of sending them for real, just send them to some dummy account (if that's even necessary). It won't take you more than 30 minutes and you'll replicate the error message and probably find the error too.
If I weren't insane: I couldn't be so brilliant! - The Joker
SykomantiS
Registered User
Posts: 14085
Joined: 06 Oct 2004, 02:00
Location: Location, Location...
Contact:

Re: Regular expression email filtering

Post by SykomantiS »

Did that before posting. Still in the dark. Which is why I made this thread.
Like I said, going through the list of emails I found nothing that would throw an application error. Yet it still did :?
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

Re: Regular expression email filtering

Post by Ron2K »

Are you sure it's the e-mail address format and not something else? I can't say for sure (combination of tiredness and Foundry at the moment), but that regex looks good to me...
Kia kaha, Kia māia, Kia manawanui.
SykomantiS
Registered User
Posts: 14085
Joined: 06 Oct 2004, 02:00
Location: Location, Location...
Contact:

Re: Regular expression email filtering

Post by SykomantiS »

As far as I can tell, the error occurred during the sending of an email (the physical mysmtp.sendmail(myEmail) line...) Or whatever it is, don't have the code in front of me right now. I compared that regex to another one I 'acquired' and the results are the same, so it should be good. Which is exactly why it's got me bugged :?

I actually don't know if it's the address format or something else, since testing would mean spamming. There's no way around this one :( Also, like I said, they didn't give me a screenie of said error.
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

Re: Regular expression email filtering

Post by Ron2K »

You would have gotten a FormatException if the e-mail address format was cooked; you did mention ApplicationException... which points to something else. ;)
Kia kaha, Kia māia, Kia manawanui.
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: Regular expression email filtering

Post by Bladerunner »

Does the system have an event log? Is there no way of checking who did not receive the email?
If I weren't insane: I couldn't be so brilliant! - The Joker
SykomantiS
Registered User
Posts: 14085
Joined: 06 Oct 2004, 02:00
Location: Location, Location...
Contact:

Re: Regular expression email filtering

Post by SykomantiS »

Not that I'm aware of. I didn't write the thing. Just have to fix it. Far as I know though, no external logs...
As far as being something else, entirely possible of course, but since looping through 300-odd students who had to be mailed (moms and dads included, so that's triple the amount of emails) only ONE exception was thrown, and was not related to memory (or out of memory, if that was your thinking)- it threw the error early on and then continued afterwards.
-Prometheus-
Resident Drama Llama
Posts: 967
Joined: 05 Mar 2008, 02:00
Contact:

Re: Regular expression email filtering

Post by -Prometheus- »

........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
BBLounge - Broadband and Technology forum
Please like our facebook page
SykomantiS
Registered User
Posts: 14085
Joined: 06 Oct 2004, 02:00
Location: Location, Location...
Contact:

Re: Regular expression email filtering

Post by SykomantiS »

Thread necro of note

Code: Select all

"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b"

Code: Select all

"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
both of these expressions allowed the following examples as accepted:
"test,mail@domian.com" <--- note comma, not period
"test1.mail@domian.com; test2.mail@domian.com" <--- two addresses separated with a semi colon.
"name@surname@domain.com" <-- 2 @ signs

Can someone please tell me why these strings are allowed, when clearly they shouldn't be?
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: Regular expression email filtering

Post by Bladerunner »

My guess is because you didn't enclose it in ^...$. But that might have undesired effects if you insert it, so test first.

Just get a new Regex off Google, there are millions of expressions available for free.
If I weren't insane: I couldn't be so brilliant! - The Joker
SykomantiS
Registered User
Posts: 14085
Joined: 06 Oct 2004, 02:00
Location: Location, Location...
Contact:

Re: Regular expression email filtering

Post by SykomantiS »

I've gone through a couple already. I've already tried the ^...$ doesn't seem to have the desired affect. :?
Post Reply