2
votes

I am trying to set up automatic email response with attachments for when a user completes a google form. One of the attachments is a zip file and the other .dmg file.From reading similar questions it looks as if the best way do this the best way is the blob function however when i try with the below code i get a attachment which is blank.I tried the mime type function also and i could not get that to work. The email does get sent but without anything in the attachment.By the code below you can probably gather i am very new to coding in google forms.

Thanks

function myFunction(e){
  var userEmail = e.values[1];
  var subject = " license key for students and staff only";
  var message = "Your SPSS license key is ************** please access 
  the files via this link 
  https://drive.google.com/drive/folders/********";


  //Get all the files from the folder
   var attachements = DriveApp.getFolderById('******')
   var blob = Utilities.newBlob('SPSS.png','SPSS_Statistics_24_mac.dmg');
   var SPSSdmg = DriveApp.getFilesByName('SPSS_Statistics_24_mac.dmg');
   var SPSSzip = DriveApp.getFilesByName('SPSS_Statistics_23_win64.zip');

   // get folder
    var folder = DriveApp.getFolderById('***');

    // get files in the folder
     var files = folder.getFiles(), file;
     while (files.hasNext()) {
     var file = files.next();
      Logger.log(attachements)
     }

     attachments: attachements

      MailApp.sendEmail(userEmail,subject,message, attachments : 
      [SPSSdmg.next(),SPSSzip.next()] {attachments: [blob]});
1

1 Answers

0
votes

How about this sample script? If files with the file name of "SPSS_Statistics_24_mac.dmg" and "SPSS_Statistics_23_win64.zip" is only one for each file, following sample script can be used. There are several files with the same file name, it has to use file ID.

Script :

function myFunction(e){
  var userEmail = e.values[1];
  var subject = " license key for students and staff only";
  var message = "Your SPSS license key is ************** please access \
  the files via this link \
  https://drive.google.com/drive/folders/********";
  var SPSSdmg = DriveApp.getFilesByName('SPSS_Statistics_24_mac.dmg').next();
  var SPSSzip = DriveApp.getFilesByName('SPSS_Statistics_23_win64.zip').next();
  MailApp.sendEmail({
    to: userEmail,
    subject: subject,
    body: message,
    attachments: [
      SPSSdmg.getBlob().setName('SPSS_Statistics_24_mac.dmg'),
      SPSSzip.getBlob().setName('SPSS_Statistics_23_win64.zip')
    ]
  });
}

If I misunderstand your question, I'm sorry.