Skip to content

Instantly share code, notes, and snippets.

@rodrigoSaladoAnaya
Created July 22, 2014 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigoSaladoAnaya/3cefdeaa66265910ebd1 to your computer and use it in GitHub Desktop.
Save rodrigoSaladoAnaya/3cefdeaa66265910ebd1 to your computer and use it in GitHub Desktop.
How validate a 'MX record' with #groovy (http://en.wikipedia.org/wiki/MX_record)
package you.mane
import javax.naming.directory.InitialDirContext
class Clazz {
static mailExchange(String email) {
def emailParts = email.split('@')
if (emailParts.size() == 2) {
try {
def domainName = emailParts[1]
def iniDir = new InitialDirContext();
def idAtrr = new String[1]
idAtrr[0] = 'MX'
def mxs = iniDir.getAttributes("dns:/${domainName}", idAtrr);
return mxs.size() > 0
} catch (e) {
//...show error
}
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment