想要发送别名的确认电子邮件

时间:2015-02-28 04:41:55

标签: google-apps-script google-form

我希望确认电子邮件的“发件人”地址来自别名帐户,而不是我的默认Google帐户。

这是我的代码。我尝试用别名电子邮件地址替换cc = Session.getActiveUser().getEmail();,但这不起作用。

/* Send Confirmation Email with Google Forms */

function Initialize() {

    var triggers = ScriptApp.getProjectTriggers();

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

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

}

function SendConfirmationMail(e) {

    try {

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

        // This is your email address and you will be in the CC
        cc = Session.getActiveUser().getEmail();

        // This will show up as the sender's name
        sendername = "EarthFest Singapore";

        // Optional but change the following variable
        // to have a custom subject for Google Docs emails
      subject = "EarthFest Tickets";

        // This is the body of the auto-reply
      message = "<center><img src='http://earthfestsingapore.com/email_logo.png' /></center><br><center>Tickets for Sept. 26, 2015.  10:30 am to 3:30 pm.</center><br>Thanks so much for joining EarthFest!  Let's make a modern and sustainable future fun, delicious, and possible!<br><br>We can't wait to see you there!  Feel free to invite your friends by sharing this link: <a href='http://goo.gl/mS5D2X'>http://goo.gl/mS5D2X</a> and we'd love to see you on:<br><br><center><a href='http://facebook.com/earthfestsingapore'><img src='http://earthfestsingapore.com/facebook_small.png' /></a>&nbsp;&nbsp;<a href='http://instagram.com/earthfestsing'><img src='http://earthfestsingapore.com/instagram_small.png' /></a>&nbsp;&nbsp;<a href='http://twitter.com/earthfestsing'><img src='http://earthfestsingapore.com/twitter_small.png' /></a>&nbsp;&nbsp;<a href='https://www.youtube.com/user/earthfestsing'><img src='http://earthfestsingapore.com/youtube_small.png' /></a></center><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["E-mail address can we send tickets"].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 :(得分:0)

您可以在sendEmail()方法的options参数中添加别名。

    GmailApp.sendEmail(sender, subject, textbody, { 
                          cc: cc, 
                          name: sendername, 
                          htmlBody: message, 
                          from: "alias@example.com"
                      });