Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. function sendEmails() {
  2. var sheet = SpreadsheetApp.getActiveSheet();
  3. var startRow = 1; // First row of data to process
  4. var numRows = 1; // Number of rows to process
  5. // Fetch the range of cells A2:B3
  6. var dataRange = sheet.getRange(1, 1, sheet.getLastRow(), 1);
  7. // Fetch values for each row in the Range.
  8. var data = dataRange.getValues();
  9. var ui = SpreadsheetApp.getUi();
  10. var response1 = ui.prompt('Email', 'Input name of text file here:', ui.ButtonSet.YES_NO);
  11. // Process the user's response.
  12. if (response1.getSelectedButton() == ui.Button.YES) {
  13. var text_file_name = response1.getResponseText();
  14. var files = DriveApp.getFilesByName(text_file_name); // Get all files with name.
  15. while (files.hasNext()) {
  16. var file = files.next();
  17. var Id = file.getId();
  18. var message = DocumentApp.openById(Id).getBody().getText();
  19. var response2 = ui.prompt('Email', 'Input email subject here:', ui.ButtonSet.YES_NO);
  20. if (response2.getSelectedButton() == ui.Button.YES) {
  21. var subject = response2.getResponseText();
  22. for (i in data) {
  23. var row = data[i];
  24. var emailAddress = row[0];
  25. var message = message;
  26. var subject = subject;
  27. MailApp.sendEmail(emailAddress, subject, message);
  28. }
  29. }
  30. }
  31. } else if (response.getSelectedButton() == ui.Button.NO) {
  32. Logger.log('The user didn\'t want to provide a name.');
  33. } else {
  34. Logger.log('The user clicked the close button in the dialog\'s title bar.');
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement