I want to add the source settings to the Google form auto reply script.

Asked 2 years ago, Updated 2 years ago, 50 views

I'm a complete script beginner.

I successfully set up the following script by searching on the Internet.
I'd like to add another source here.

GmailApp.sendEmail(address, title, body, {
  from: 'email address', name: 'sender'
});

I tried the above description by trial and error, but
There is no basic syntax concept, so the error failed to set it up properly.

I would be very happy if anyone could tell me.Thank you for your cooperation.
I would like to add it to the script below and set it up successfully.

 function sendMailGoogleForm(){
  Logger.log('sendMailGoogleForm()debug start');

  //------------------------------------------------------------
  // Configuration Area From Here
  //------------------------------------------------------------

  // Subject, Body, Footer
  var subject="[Acceptance slip]";
  var body
   = This is ●●.\n"
  + "Thank you very much for your recent application.\n"
  + "We look forward to seeing you on the day.\n\n"
  + "\n\n"
  + "----------------------------------------------------------------------\n";
  var footer
  = US>"----------------------------------------------------------------\n"
  + "";

  // Specifying the Input Column Name
  var NAME_COL_NAME = 'Name';
  varMAIL_COL_NAME = 'Mail Address';
  var address="";

  // Mail To
  var admin="event@events.●●.jp";// Administrator (required)
  varcc="; // Cc:
  var bcc = admin; // Bcc:
  var reply=admin;// Reply-To:
  var to = "; // To: (The address of the input person is automatically entered)

  //------------------------------------------------------------
  // Configuration Area Up to here
  //------------------------------------------------------------

  try{
    // Working with Spreadsheets
    varsheet=SpreadsheetApp.getActiveSheet();
    varrows=sheet.getLastRow();
    varcols=sheet.getLastColumn();
    varrg=sheet.getDataRange();
    Logger.log("rows="+rows+"cols="+cols);

    // Email subject/text creation and destination email address acquisition
    for(vari=1;i<=cols;i++){
      varcol_name = rg.getCell(1,i).getValue(); // Column Name
      varcol_value=rg.getCell(rows, i).getValue(); // Input value
      body+="["+col_name+"]\n";
      body+=col_value+"\n\n";
      if(col_name===NAME_COL_NAME){
       body=col_value+"Dear\n\n"+body;
      }
      if(col_name===MAIL_COL_NAME){
       to=col_value;
      }
    }
    body+=footer;

    // Destination Options
    var options={};
    if(cc)options.cc =cc;
    if(bcc) options.bcc = bcc;
    if(reply)options.replyTo=reply;

    // sending an e-mail
    if(to){
      MailApp.sendEmail(to, subject, body, options);
    } else {
      MailApp.sendEmail(admin, "[Failure] No email address specified in Google form", body);
    }
  }catch(e){
    MailApp.sendEmail(admin, "[Failure] Error sending mail from Google form", e.message);
  }
}

google-apps-script

2022-09-30 20:11

1 Answers

For GmailApp sendMail options from
You must be registered with the alias or surrogate sender of the running G account.
I think it's a security reason.If you can specify your favorite email address, it's spam.

I recently created a similar tool.
The proxy sender sends an email from Google to the designated email address and
You can configure it by entering the authentication code written there.

For aliases, why don't you refer to this?
https://www.ka-net.org/blog/?p=4441

Either way, open the running account's Gmail in your browser and
If the sender of the new mail can be selected, it will be successful.


2022-09-30 20:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.