简体   繁体   中英

Filling Google Forms with Google Sheets

I have an HTML form which saves its responses to a Google Sheet. The form contains the following fields:

Name:
Email:
Subject:
Message:

Now, what I want is

Is there a way to send these e-mails automatically? The format of the email is as follows:

From: <my email address>
To: <email address from the "Email" field in the spreadsheet>
Subject: Re: Submission Received

Hey <name from the "Name" field in the spreadsheet>!

Body of the mail

If you have the data in google sheets, then you can handle your automation there. I setup this sample file that you could probably base your data set on.

From there I attached the below script to the spreadsheet. You would then need to set a trigger to execute this script on a somewhat regular frequency (5 minutes? 1 minute?). I think it should accomplish what you are going for. There's a check built in to ensure that partial data is not sent.

const ss = SpreadsheetApp.getActiveSheet();
const sentMessageColumn = ss.getRange("E:E").getColumn();
function regularProcedure(){
  var aCell = ss.getRange(ss.getLastRow(),sentMessageColumn)

  while(aCell.isBlank()){
    var eRow = aCell.getRow();
    
    if(!(ss.getRange(eRow,2).isBlank() ||
      ss.getRange(eRow,3).isBlank() ||
      ss.getRange(eRow,4).isBlank()))
      {
        var newMail = GmailApp.createDraft(
        ss.getRange(eRow,2).getValue(),
        ss.getRange(eRow,3).getValue(),
        ss.getRange(eRow,4).getValue());
        newMail.send();
        aCell.setValue(true);
        }      
      aCell=aCell.offset(-1,0);
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM