Skip to content

Instantly share code, notes, and snippets.

@cnicodeme
Last active August 29, 2015 14:25
Show Gist options
  • Save cnicodeme/1c6529b5723f5c25a0e5 to your computer and use it in GitHub Desktop.
Save cnicodeme/1c6529b5723f5c25a0e5 to your computer and use it in GitHub Desktop.
Function to verify if an email exists inside a Google Spreadsheet
/**
* Verify that the provided email is well recognized by the MX server.
*
* @param {string} token : The API token bought at https://voilanorbert.com
* @param {string} email : The email to verify
*
* @return Boolean as 1/0 if it exists or an error code (starting with "ERR-{code}")
*
* @customfunction
*/
function VN_VERIFY_EMAIL(token, email) {
if (!token) return "Please provide a token.";
if (!email) return "Please provide an email.";
var request = UrlFetchApp.fetch("https://www.voilanorbert.com/api/v2/verify", {
'method': 'post',
'muteHttpExceptions': true,
'payload': {
'token': token,
'email': email
}
});
var objRequest = Utilities.jsonParse(request.getContentText()),
response = null;
switch(request.getResponseCode()) {
case 204:
response = "1";
break;
case 404:
response = "0";
break;
default:
if (objRequest.code) {
response = 'ERR-' + objRequest.code + ' : ' + objRequest.error;
break;
}
response = 'ERR-' + objRequest.error;
}
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment