如何通过提交者(Google App Script)发送回复电子邮件

时间:2014-05-15 17:31:48

标签: javascript forms google-apps-script

我有一个提交电子表格的Google表单。然后我写了这段代码,发送一封包含结果的电子邮件。谁能告诉我如何通过提交表格的人提交电子邮件?

function Initialize(){

var triggers = ScriptApp.getScriptTriggers();

for (var i in triggers) {
    ScriptApp.deleteTrigger(triggers[i]);
}

ScriptApp.newTrigger("SendConfirmationMail")
    .forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
    .onFormSubmit()
    .create();

} 函数SendConfirmationMail(e){

try {
    var ss, cc, subject, columns;
    var message, value, textbody, sendername, sender;

    // This is my email address and I will be in the CC
    cc = e.namedValues["Username"].toString();

    // This will show up as the sender's name
    sendername = e.namedValues["Name"].toString();

    subject = "Ticket Submitted";

    message = "We have received your details.<br>Thanks!<br><br>";

    ss = SpreadsheetApp.getActiveSheet();
    columns = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];

    // This is the submitter's email address
    sender = e.namedValues["Username"].toString();

    // Only include form values that are not blank
    for ( var keys in columns ) {
        var key = columns[keys];
        if ( e.namedValues[key] ) {
            message += key + ' :: '+ e.namedValues[key] + "<br />"; 
        }
    }
    textbody = message.replace("<br>", "\n");
    GmailApp.sendEmail(sender, subject, textbody, 
                        {cc: cc, name: sendername, htmlBody: message});
} catch (e) {
    Logger.log(e.toString());
}

}

1 个答案:

答案 0 :(得分:1)

这是不可能的,也不应该。你想在未经他们同意的情况下冒充他人。

遗憾的是,古老的电子邮件系统允许这样做,从而使垃圾邮件制造者和网络钓鱼诈骗的生活更加轻松。但谷歌和其他互联网公司努力防止和过滤这类电子邮件。

另一方面,除非是Gmail中的授权帐户,否则您将无法通过Google应用向其他人发送电子邮件。

您可以做的最好的事情是设置reply-to地址。