【问题标题】:Google Form mail notification script. Emails always have "me" as senderGoogle Form 邮件通知脚本。电子邮件始终将“我”作为发件人
【发布时间】:2018-10-24 07:17:32
【问题描述】:

我尝试使用搜索功能,但没有找到解决问题的方法,或者我还不够了解。

我为谷歌表单编写了一个脚本,当用户提交表单时,它会自动向两个电子邮件地址发送一封电子邮件。我已经构建了一些应该在电子邮件主题中显示的信息,并将表单中的输入放入电子邮件中,并带有一些简单的 HTML 格式。

我的问题是,电子邮件始终将我的电子邮件地址作为发件人(我用于创建表单的帐户) 我想要发件人的电子邮件,即提交表单的电子邮件。 这怎么可能?

代码如下:

    function sendFormByEmail(e) 
{    
  // Sent to Email address
  var email1 = "123@abc.com";
  var email2 = "345@abc.com"; 


  // Variables

  var s = SpreadsheetApp.getActiveSheet();
  var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
  var txt = "";
  var subject = "Example text: ";

  // Var e = form input as array.
  // Loop through the array.

  for(var i in headers){
    txt += "<b>" + headers[i] + '</b>' + ': '+ 
e.namedValues[headers[i]].toString() + '<br><br>';    
  }

  // Insert variables from the spreadsheet into the subject.
  // Create email subject
  subject += "Example text " + e.namedValues[headers[2]].toString();

  // Send the email
  MailApp.sendEmail(email1, subject, "", {htmlBody:txt});
  MailApp.sendEmail(email2, subject, "", {htmlBody:txt}); 

}

【问题讨论】:

    标签: email google-apps-script notifications google-forms


    【解决方案1】:

    由于脚本是从用户帐户运行的,因此无法以提交表单的用户身份发送邮件,并且邮件应用程序将仅从该帐户发送邮件。您可以通过参数name根据提交表单的用户名更改显示名称。您还可以通过在 mailApp 语法中添加参数 noReply 将电子邮件更改为 noreply@domainName.com。但是您不能将其更改为提交表单的用户

    以上参数可以参考这个文档:https://developers.google.com/apps-script/reference/mail/mail-app

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-08
      • 2018-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多