Home>

Create a script to send the following mail and main works without any problem. I added a PDF capacity to this and created a PDF with a script that sends an email over 50KB, but it doesn't work. Would you please correct it? Thank you.

I added only the following parts in the upper and lower parts, but no error occurred and no result was obtained.

var values ​​= sheet.getRange (2, 3, sheet.getLastRow () --1, 6) .getValues ​​();// Get a list of email addresses and company names
let targets = sheet.getRange (2, 3, sheet.getLastRow () --1, 5) .getValues ​​()
var value = {};// Replace "% company name%" in the text with the company name and send an email
var count = values.length;
for (var i = 0;i<= count-1;i ++)
{
value [i] = values ​​[i]
if (value [i]>= 50000)
{
let targets = sheet.getRange (2, 3, i, 5) .getValues ​​()
function sendAllMail00 () {
  // Get the execution date of this script
 var today = Utilities.formatDate (new Date (),'Asia/Tokyo','yyyy/MM/dd') ;;// Get today's date in yyyy/mm/dd format
  // Get the spreadSheet object
 let spreadSheet = SpreadsheetApp.getActive ()
 // Get a sheet object with the subject and body
 let templateSheet = spreadSheet.getSheetByName ("data item")
 // Get the value because the subject is in cell D2
 let title = templateSheet.getRange ("D2"). getValue ()
 // Get a sheet with a list of email addresses to send
 let sheet = spreadSheet.getSheetByName ("answer")
 // Get a list of email addresses and company names
 let targets = sheet.getRange (2, 3, sheet.getLastRow () --1, 5) .getValues ​​()
 // Send an email by replacing "% company name%" in the text with the company name
  for (target of targets) {
   try {
    var fileurls = target [4] .split ('/');
    var fileid = fileurls [5];
    var file = DriveApp.getFileById (fileid);// Get attachments
    // The text is in cell B2, so get that value
    let body = templateSheet.getRange ("E2"). getValue ()
    body = body.replace (/% name% /, target [0])
    // Send an email with the spreadsheet email address, subject and body
    GmailApp.sendEmail (target [1], title, body, {attachments: [file]});
    }
   catch (e) {
    continue;continue;
   }
  }
 }
function sendAllMail00 () {
    // Get the execution date of this script
   var today = Utilities.formatDate (new Date (),'Asia/Tokyo','yyyy/MM/dd') ;;// Get today's date in yyyy/mm/dd format
    // Get the spreadSheet object
   let spreadSheet = SpreadsheetApp.getActive ()
   // Get a sheet object with the subject and body
   let templateSheet = spreadSheet.getSheetByName ("data item")
   // Get the value because the subject is in cell D2
   let title = templateSheet.getRange ("D2"). getValue ()
   // Get a sheet with a list of email addresses to send
   let sheet = spreadSheet.getSheetByName ("answer")
   var values ​​= sheet.getRange (2, 3, sheet.getLastRow () --1, 6) .getValues ​​();
   var value = {};
   var count = values.length;
   for (var i = 0;i<= count-1;i ++)
   {
    value [i] = values ​​[i]
    if (value [i]>= 50000)
    {
      let targets = sheet.getRange (2, 3, i, 5) .getValues ​​()
        for (target of targets) {
          try {
          var fileurls = target [4] .split ('/');
          var fileid = fileurls [5];
          var file = DriveApp.getFileById (fileid);// Get attachments
      // The text is in cell B2, so get that value
          let body = templateSheet.getRange ("E2"). getValue ()
          body = body.replace (/% name% /, target [0])
・ ・ ・ Same after that