Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sendEmails() {
- var sheet = SpreadsheetApp.getActiveSheet();
- var startRow = 1; // First row of data to process
- var numRows = 1; // Number of rows to process
- // Fetch the range of cells A2:B3
- var dataRange = sheet.getRange(1, 1, sheet.getLastRow(), 1);
- // Fetch values for each row in the Range.
- var data = dataRange.getValues();
- var ui = SpreadsheetApp.getUi();
- var response1 = ui.prompt('Email', 'Input name of text file here:', ui.ButtonSet.YES_NO);
- // Process the user's response.
- if (response1.getSelectedButton() == ui.Button.YES) {
- var text_file_name = response1.getResponseText();
- var files = DriveApp.getFilesByName(text_file_name); // Get all files with name.
- while (files.hasNext()) {
- var file = files.next();
- var Id = file.getId();
- var message = DocumentApp.openById(Id).getBody().getText();
- var response2 = ui.prompt('Email', 'Input email subject here:', ui.ButtonSet.YES_NO);
- if (response2.getSelectedButton() == ui.Button.YES) {
- var subject = response2.getResponseText();
- for (i in data) {
- var row = data[i];
- var emailAddress = row[0];
- var message = message;
- var subject = subject;
- MailApp.sendEmail(emailAddress, subject, message);
- }
- }
- }
- } else if (response.getSelectedButton() == ui.Button.NO) {
- Logger.log('The user didn\'t want to provide a name.');
- } else {
- Logger.log('The user clicked the close button in the dialog\'s title bar.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement