Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: validate email without regular expressions

Since Delphi does not have any regular expressions library built-in, have you seen a good function to validate email addresses at least to some degree in using only Delphi RTL/VCL?

I don't want to link additional *.dll to my product integrating regular expression support and I need also Delphi 7 compatibility. Embedding regex library into exe increases it's size and I doubt it worths adding next 100k because you just need 10-50-lines function of email validation.

like image 950
Vladislav Rastrusny Avatar asked Aug 25 '10 12:08

Vladislav Rastrusny


2 Answers

As requested I'm making my comment an answer..

http://www.howtodothings.com/computers/a1169-validating-email-addresses-in-delphi.html

Thanks!

like image 97
Marko Avatar answered Sep 16 '22 14:09

Marko


The big problem on email address validation is that RFC 822 is so broad, that no regular expression will help.

The article I Knew How To Validate An Email Address Until I Read The RFC describes this well.
It quotes the RFC the local-part MUST be interpreted and assigned semantics only by the host specified in the domain part of the address (the local part is the part before the @ sign in an email address).

So:
the only way to check if an email address is valid, is to setup an SMTP connection to the host accepting mail for that particular domain, and start up the email handshaking process with the email address you are trying to verify.

This is what a lot of anti-SPAM software does to verify sender email addresses: they contact the SMTP server of the sender of the email, try to setup an SMTP handshake, and if that goes OK, they rate the incoming email as more like to not be SPAM.

You can use the Indy SMTP client component to send mail; the accepted answer to this question explains how.

--jeroen

like image 44
Jeroen Wiert Pluimers Avatar answered Sep 19 '22 14:09

Jeroen Wiert Pluimers