Created
July 22, 2014 20:32
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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