Skip to content

Instantly share code, notes, and snippets.

@lincolnmurphy
Last active December 20, 2015 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lincolnmurphy/6066175 to your computer and use it in GitHub Desktop.
Save lincolnmurphy/6066175 to your computer and use it in GitHub Desktop.
GMail is making a lot of changes lately... wouldn't it be nice to know who - other than those with a gmail.com email address - are using GMail and help them ensure they continue to get your emails? Here's one way using JavaScript and node.js.
// written to run in the console
// using node.js
// by a non-programmer... no warranties here.
// Use at your own risk!
// http://twitter.com/lincolnmurphy
// I probably can't help you with programming issues,
// but feel free to follow me
var dns = require('dns'),
fs = require('fs');
// I used a file in the same directory as the script
// each line has one email address and that's all
// no commas, tabs etc.
// make sure there are no headers (if you copy from a CSV or Excel this might happen)
// and ensure there aren't any extra blank lines at the bottom
// or modify the script to deal with those issues...
var path = "email.txt";
var emails = fs.readFileSync(path).toString().split('\n'); //synchronous
// if an email has a domain from one of these
// they are obviously not GMail so we don't care
// Also, if they have gmail.com as their email address,
// you don't need to run them through this script... :-)
// these are the most common non-GMail public email system domains
// on my list... you may find others
var excludeDomains = [
'gmail.com',
'yahoo.com',
'googlemail.com',
'live.com',
'outlook.com',
'hotmail.com',
'rocketmail.com',
'me.com',
'att.net',
'yahoo.ca']
//console.log("we're going to check this many emails: " + emails.length);
for(var o=0;o<emails.length;o++){
var iEmail = emails[o];
// console.log(iEmail);
var iDomain = emails[o].replace(/.*@/, "");
// console.log(iDomain);
// most GMail MX records have either or both of these domains
// I just looked throught he JSON object as a string for those
// no need to get fancy; if one of those is there, they're on GMail
// though you can get as fancy as you want
var mxValue = 'google.com';
var mxValueTwo = 'googlemail.com';
var goodToGo = "yes"
for(var e=0;e<excludeDomains.length;e++){
console.log("the current domain is " + iDomain + " and the excluded domain is " + excludeDomains[e]);
if(iDomain === excludeDomains[e]){
goodToGo = "no";
}
}
// if the domain is not on our excluded list
// do the lookup (this happens behind the scenes)
// kinda cool node.js stuff going on here, BTW
if(goodToGo === 'yes'){
doLookup(iDomain, iEmail);
}
}
console.log("it's running in the background... asynchronously");
// in the same directory as this script
// I created a file called results.txt
// it just writes a new line to the file
// every time there's a result or an error
// it writes the email address, a tab, then the result
// this will allow you to easily copy and paste into
// Excel or a Google Spreadsheet
// You could output to a web page or dump to Google Drive via API
// I took the easy way out
// oh, and the error handling is 'dumb'
// it just writes that there was an error - likely a timeout -
// so you can put those email addresses back in the
// source file and try again.
function doLookup(dDomain, dEmail) {
dns.resolveMx(dDomain, function (err, addresses) {
if (err) {
fs.appendFile('results.txt', dEmail + "\t'Error'\n", function (err) {
});
return(null);
}
var stAttrValue = JSON.stringify(addresses);
var stLcAttrValue = stAttrValue.toLowerCase();
if (stLcAttrValue.indexOf(mxValue) !== -1 || stLcAttrValue.indexOf(mxValueTwo) !== -1){
fs.appendFile('results.txt', dEmail + "\tY\n", function (err) {
});
}
else {
fs.appendFile('results.txt', dEmail + "\tN\n", function (err) {
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment