How can I populate the Reply To field in an email based on cell value from a Google Sheet?

  Kiến thức lập trình

I recently asked a question about getting cell values included in an email sent by an Google App Script and have a related question with grabbing the “email” column cell data to populate the “reply to” field of the email.

I’m not certain on how to properly word this question so I will over-explain in hopes it helps.

Right now, the process goes as follows:

  1. a customer comes to the company website
  2. fills out a Google Form (which, among other bits of information, includes their email address)
  3. the data from the Google Form gets plugged into a new row of a Google Sheet document
  4. a script then runs sending an email (from our gmail account) with the row’s cell values to a pre-defined destination email address (in this case, a single yahoo account).

That all works great now!

What I am asking is if there is a way to grab the cell value (in this case their email address) and automatically put it as the reply-to address of the automated email that gets sent? So when we respond to one of these automated emails (it’s a bid request) it will reply to the customer’s email (they provided this in the Google Form that then transferred to Google Sheets where the email script ran). Right now, the reply-to email is our own gmail account that was used to send the email.

Here is the script:

// this function will fires automatically 
// it grabs all data from the last row and send it via email

function send_email() {
  var header = SpreadsheetApp.getActive().getDataRange().getValues().shift();
  var row = SpreadsheetApp.getActive().getDataRange().getValues().pop();
  var message = "";
  for (var i = 0; i < header.length; i++) {
    message += header[i] + ": " + row[i] + "nn";
  var subject = 'Request for Bid';
  var address = '[email protected]';
  GmailApp.sendEmail(address, subject, message);

Hopefully I provided enough information and thanks for any and all help!

I have searched here but am unable to find the answer (probably due to not knowing how to word the question correctly).

New contributor

sand4sale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.