Created
July 28, 2011 01:30
-
-
Save nickstamas/1110742 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sendEmails() { | |
| var doc = SpreadsheetApp.getActiveSpreadsheet(); | |
| var sheet = doc.getSheets()[0]; // <--- First sheet has index 0 | |
| //Browser.msgBox(sheet.getName()); | |
| var startRow = sheet.getLastRow(); // First row of data to process | |
| //Browser.msgBox(startRow); | |
| // Fetch the range of cells A2:B3 | |
| //getRange looks for this order of parameters: Starting Row, Leftmost Column, Number of Rows to look at, number of columns to look at | |
| var dataRange = sheet.getRange(startRow, 4, 1, 11) ; | |
| // Fetch values for each row in the Range. | |
| var data = dataRange.getValues(); | |
| //Browser.msgBox(data[0]); | |
| var row; | |
| for (i in data) { | |
| row = data[i]; | |
| //Browser.msgBox(row[2]); | |
| //check the location and match correct email address | |
| var emailAddress = 'demetristamas@gmail.com'; | |
| if (row[2] == 'Windsor') { | |
| emailAddress = 'demetristamas@gmail.com'; | |
| } else if (row[2] == 'Wilmington') { | |
| emailAddress = 'smelly@gmail.com'; | |
| } else if (row[2] == 'Ramsey') { | |
| emailAddress = 'manny@gmail.com'; | |
| } else if (row[2] == 'Belstville') { | |
| emailAddress = 'record@gmail.com'; | |
| } else if (row[2] == 'Test') { | |
| emailAddress = 'dstamas@gmail.com'; | |
| } | |
| var subject = "Parts Request"; | |
| //Browser.msgBox(emailAddress); | |
| var message = '<html><body><b>1st Part Number: </b>' + row[10] | |
| + '<br><b>2nd Part Number: </b>' + row[6] | |
| + '<br><b>3rd Part Number: </b>' + row[7] | |
| + '<br><b>Incident Number: </b>' + row[1] | |
| + '<br><b>Technician Name: </b>' + row[3] | |
| + '<br><b>Ship To Address: </b>' + row[4] | |
| + '<br><b>Technician Email: </b>' + row[8] | |
| + '<br><b>Notes: </b>' + row[9] | |
| + '</html></body>'; // Second column | |
| MailApp.sendEmail(emailAddress, subject, message, {replyTo: emailAddress,htmlBody: message}); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment