Bulk Email Customers via Script

  1. Open you Google Sheet and make sure the emails are listed in the last column and the header ( first row) is “EMAIL”!

    Screenshot 2025-02-20 at 10.44.07.png

  2. Now open the script template here

  3. Make sure you have the “send email.gs” open and replace the following variables manually:

    1. “SHEETID” → take the Id from your google sheet list

      Screenshot 2025-02-20 at 10.45.24.png

    2. “SHEETNAME” → take the sheet page name from your google sheet

      Screenshot 2025-02-20 at 10.46.10.png

    3. “BETREFF” → paste your subject

    4. “EMAILBODY” → paste your email body

<aside> <img src="/icons/warning_red.svg" alt="/icons/warning_red.svg" width="40px" />

Make sure to paste alle information formatted correctly! Always inside the `` or ""

</aside>

function sendEmails() {
  const sheetId = "SHEETID"; //REPLACE SHEETID HERE
  const spreadsheet = SpreadsheetApp.openById(sheetId);
  const sheet = spreadsheet.getSheetByName("SHEETNAME"); //REPLACE SHEETNAME HERE
  const lastColumn = sheet.getLastColumn();
  const header = sheet.getRange(1, lastColumn).getValue();
  if (header.toString().trim().toUpperCase() !== "EMAIL") {
    throw new Error("The last column header is not 'EMAIL'. Please check your sheet.");
  }
  const emailData = sheet.getRange(2, lastColumn, sheet.getLastRow() - 1, 1).getValues();

  const subject = "BETREFF"; //REPLACE BETREFF HERE
  const body = `EMAILBODY`; //REPLACE EMAILBODY HERE

  const sentEmails = new Set();

  for (let i = 0; i < emailData.length; i++) {
    const email = emailData[i][0].trim(); 

    if (email && !sentEmails.has(email)) {
      try {
        GmailApp.sendEmail(email, subject, body, {
          replyTo: "[email protected]",
          name: "ahead Support Team"
        });
        sentEmails.add(email);
        Logger.log(`Email sent to: ${email}`);
      } catch (e) {
        Logger.log(`Failed to send email to: ${email}. Error: ${e.message}`);
      }
    }
    if ((i + 1) % 10 === 0) {
      Utilities.sleep(5000);
    }
  }
}
  1. When everything is filled in correctly, save the Script and click on ”Run”.

  2. Select and accept all necessary rights from your Google Account to continue.

    Screenshot 2025-02-20 at 10.57.25.png

  3. Execution will start and you can track status on the bottom “Execution log”