← All Apps Scripts templates
/
Find verified emails

Find verified emails

  1. Create a new Google Sheets file
  2. Name it “email verification” and leave it blank (always keep it on your workspace)
  3. Take the ID of the spreadsheet you created. You can find it in the URL in the screenshot below:
custom spreadsheet id
The custom spreadsheet ID when you create a new Google Sheets file (required)

4. Go back to your Google Sheet that contains the code and the “Find email” button
5. Go to Apps Scripts: Extensions > Apps Script
6. Paste the Spreadsheet ID
7. Save your project and go back to your sheet
8. Add your data and use the find email button to launch the finder

It adds the email to a spreadsheet:

  • If there is an error, it means the email is invalid
  • If there is no error, it means it is valid

The code to paste in Apps Script inside Google Sheets:


function validateEmail(email) {
  
  var re = /\S+@\S+\.\S+/;
  if (!re.test(email)) {
    return false;
  } else {
    var testSheet = SpreadsheetApp.openById("YOUR SPREADSHEET ID");
    try {
      testSheet.addViewer(email);
    } catch(e) {
      console.log("not verified", email)
      return false;
    }
    testSheet.removeViewer(email);
    console.log("verified", email)
    return true;
  }
}

function findEmails(){
// Get data from the spreadsheet
  var data = SpreadsheetApp.getActiveSheet().getDataRange().getValues();

// Create variables
  let first_name_column = ""
  let last_name_column = ""
  let domain_column = ""
  let email_column = ""

// Create array with variables
  let variables = [first_name_column, last_name_column, domain_column, email_column]

  data[0].forEach((item,index)=>{

// Get column number for each variables
    if (item == "first_name"){first_name_column=index}
    if (item == "last_name"){last_name_column=index}
    if (item == "domain"){domain_column=index}
    if (item == "email"){email_column=index}
  })

data.forEach((row,index) => {

  first_name=row[first_name_column]
  last_name=row[last_name_column]
  domain=row[domain_column]

  let values = [first_name, last_name, domain]
  let rowValid = values.includes("") ? false:true

// find email
  if (rowValid){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  // ss is now the spreadsheet the script is associated with
  var sheet = ss.getSheets()[0]; // sheets are counted starting from 0
  // sheet is the first worksheet in the spreadsheet
  var cell = sheet.getRange(index+1, email_column+1);
  if (index != 0){
    console.log(findEmail(first_name,last_name,domain))
    cell.setValue(findEmail(first_name,last_name,domain))
    }   
  } else { // return missing data

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  // ss is now the spreadsheet the script is associated with
  var sheet = ss.getSheets()[0]; // sheets are counted starting from 0
  // sheet is the first worksheet in the spreadsheet
  var cell = sheet.getRange(index+1, email_column+1);
  cell.setValue("Missing Data Input")
  }
})
}

function findEmail(firstName, lastName, domain) {

  var n = {
        "first_name": firstName.toLowerCase(),
        "first_initial": firstName[0].toLowerCase(),
        "last_name": lastName.toLowerCase(),
        "last_initial": lastName[0].toLowerCase(),
    };

    // create permutations
    var possibilities = [
        "{fn}",
        "{fn}.{ln}",
        "{fi}{ln}",
        "{fn}{ln}",
        "{fn}{li}",
    ];

    var emails = [];
    for (var i=0; i {
      let result = validateEmail(item)
      console.log(result)
      if (result == true) {
        console.log(item, result)
        resultEmail = item
        return "email found"
        
      } else {
        return "no email found"
       }       
    })
    return resultEmail
}

Reach us if the process is unclear or if the script is outdated
Apps Scripts template

Find verified emails

Last updated
3/4/2023
Built by
Avatar Placeholder
internal