grails email validator
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
grails-app email validator plugin Aug 20, 2010
src/groovy/grails/plugins/emailvalidator email validator plugin Aug 20, 2010
web-app/WEB-INF email validator plugin Aug 20, 2010
EmailValidator-grailsPlugins.iml email validator plugin Aug 20, 2010
EmailValidator.iml email validator plugin Aug 20, 2010
EmailValidatorGrailsPlugin.groovy email validator plugin Aug 20, 2010
License.txt email validator plugin Aug 20, 2010 added link to spec Aug 20, 2010

Grails Email Validator Plugin

The Email Validator plugin provides extensive checking of email addresses.

What does it do?

It helps answer the following questions:

  • Does this email have valid syntax?
  • Does this domain exist?
  • Can I send an email to this domain?
  • Does the user exist in this mail domain?

How do I use it?

In your code, call:

EmailStatus status = EmailValidatorService.check( "" ) 

This will return an EmailStatus object. It has the following properties

boolean syntaxValid   // the address entered has valid email syntax 
boolean domainValid   // the domain exists and mail servers can connect to it
boolean verified      // the user exists in the remote mail server

Additionally, there is a subfield in EmailStatus called SmtpServer, which provides the following information:

String domain					// email domain name
String mxRecord					// name of preferred mx record
boolean valid 					// has a MX record for the mail server
boolean canConnect 				// can connect to this SMTP server
boolean acceptsVerifyRequests 	// can accept VRFY calls


These options are configurable via your application's Config.groovy file:

PropertyDefault ValueWhat does it do?
emailvalidator.checkDomainstruewhen enabled, will check a domain name for validity and try to see if a mail connection can be made.
emailvalidator.checkVRFYfalsewhen enabled, will issue a VRFY command to see if the user exists in the remote mail server. Little utility in reality since most servers would have this disabled
emailvalidator.useCachetrueuses a database cache to store smtp requests. This means that common domains ( like gmail ) are only checked once until your database melts down.

Implementation details

  • Email syntax validation is done via the Apache Commons EmailValidator.

  • Domain validity is calculated by getting the first MX Record for that domain and trying to connect to it.

  • The validity of an email is checked by issuing a VRFY command to the server. In most cases, this would be turned off.

  • For usage examples, please refer to the EmailValidatorServiceSpec1 integration test.

Gotchas / Tips

  • If you don't want to do domain checking, it is preferrable to use the Apache Commons EmailValidator rather than this whole plugin.

  • If you disable domain checking, the smtpServer property will be null.

  • Most mail servers will have the VRFY field disabled to prevent spam. This means that in most cases, you won't know if an email address is 100% valid unless you send an email to it. The verified field of the email status is going to most often be false.