-
Notifications
You must be signed in to change notification settings - Fork 0
/
code
65 lines (54 loc) · 4 KB
/
code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var EMAIL_SENT = 'EMAIL_SENT';
/**
* Sending non-duplicate mail, to specific people using triggers.
*/
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 1; // First row of data to process. No need to change.
var numRows = 9; // Number of rows to process (Count from A, B, C etc.)
var lastRow = sheet.getLastRow(); //Get the last row.
var maxRows = sheet.getMaxRows(); //Get the max rows.
var dataRange = sheet.getRange(startRow, 1, lastRow, 9); //Collect data from this range.
var data = dataRange.getValues(); // Collect the data from the range.
for (var i = 0; i < data.length; ++i) {
var row = data[i];
// **********************************************************
// Copy the code below ****
//The part between all the stars, is the part you need to copy, paste and edit for your triggers.
if (row[1] == "Hi I am a trigger" ) { // This needs to be spelled correctly.
var message = ("Hi, this is the message inside the mail."); // You could also pick a row for the message if needed.
var emailSent = row[7]; // This is the row 8 or H because now, the row is the column, okay?
if (emailSent != 'EMAIL_SENT') { // Prevents sending duplicates. Basically if column H is anything different than EMAIL_SENT, proceed with mail.
var subject = 'This is the subject of the mail.'; // The subjet.
MailApp.sendEmail('youremailhere', subject, message); // You can comment out this line for testing with "//"
sheet.getRange(startRow + i, 8).setValue(EMAIL_SENT); // Sets the non-duplicate trigger in column H. (Row 8..)
SpreadsheetApp.flush(); // Make sure the cell is updated right away in case the script is interrupted
}} //These are important, don`t forget to copy.
//Copy the code above ****
// **********************************************************
//The part between all the stars, is the part you need to copy, paste and edit for your triggers.
if (row[1] == "Me also trigger" ) { // This needs to be spelled correctly.
var message = ("Hi, this is the message inside the mail."); // You could also pick a row for the message if needed.
var emailSent = row[7]; // This is the row 8 or H because now, the row is the column, okay?
if (emailSent != 'EMAIL_SENT') { // Prevents sending duplicates. Basically if column H is anything different than EMAIL_SENT, proceed with mail.
var subject = 'This is the subject of the mail.'; // The subjet.
MailApp.sendEmail('youremailhere', subject, message); // You can comment out this line for testing with "//"
sheet.getRange(startRow + i, 8).setValue(EMAIL_SENT); // Sets the non-duplicate trigger in column H. (Row 8..)
SpreadsheetApp.flush(); // Make sure the cell is updated right away in case the script is interrupted
}} //These are important, don`t forget to copy.
// **********************************************************
/* SAFETY COPY START
// Copy the code below ****
//The part between all the stars, is the part you need to copy, paste and edit for your triggers.
if (row[1] == "Hi I am a trigger" ) { // This needs to be spelled correctly.
var message = ("Hi, this is the message inside the mail."); // You could also pick a row for the message if needed.
var emailSent = row[7]; // This is the row 8 or H because now, the row is the column, okay?
if (emailSent != 'EMAIL_SENT') { // Prevents sending duplicates. Basically if column H is anything different than EMAIL_SENT, proceed with mail.
var subject = 'This is the subject of the mail.'; // The subjet.
MailApp.sendEmail('youremailhere', subject, message); // You can comment out this line for testing with "//"
sheet.getRange(startRow + i, 8).setValue(EMAIL_SENT); // Sets the non-duplicate trigger in column H. (Row 8..)
SpreadsheetApp.flush(); // Make sure the cell is updated right away in case the script is interrupted
}} //These are important, don`t forget to copy.
//Copy the code above ****
SAFETY COPY END */
}}