Open you Google Sheet and make sure the emails are listed in the last column and the header ( first row) is “EMAIL”!
Now open the script template here
Make sure you have the “send email.gs” open and replace the following variables manually:
“SHEETID” → take the Id from your google sheet list
“SHEETNAME” → take the sheet page name from your google sheet
“BETREFF” → paste your subject
“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);
}
}
}
When everything is filled in correctly, save the Script and click on ”Run”.
Select and accept all necessary rights from your Google Account to continue.
Execution will start and you can track status on the bottom “Execution log”