我正在发送确认邮件,其中包含谷歌文档脚本中的以下代码。
但它是从我的个人gmail地址发送的。我需要定义不同的邮件地址。因为我将在我的公司和邮件中使用它,需要像这样显示sometest@companytsite.com
我该怎么做呢?
我的代码:
function Initialize() {
var triggers = ScriptApp.getScriptTriggers();
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 = "Your Name Goes Here";
// Optional but change the following variable
// to have a custom subject for Google Docs emails
subject = "Google Form Successfully Submitted";
// This is the body of the auto-reply
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["Email Address"].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());
}
}发布于 2014-07-31 16:03:10
根据文档:https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String,Object)您应该能够在选项中传入一个from。
GmailApp.sendEmail(sender, subject, textbody, {
from: "sometest@companytsite.com",
cc: cc,
name: sendername,
htmlBody: message
});注意:为避免混淆,sender应真正为to
现在它还说,你想要发送它的电子邮件地址必须是一个别名,要检查,你可以打印出getAliases(),看看它是否存在。如果没有,您应该能够按照以下说明进行操作:
https://stackoverflow.com/questions/25052862
复制相似问题