我正在尝试编写一个脚本,根据模块发送电子邮件到不同的地址,即空气,水..
function emailspecialist() {
var sheet = SpreadsheetApp.openById("15Om5F29GIlu77rQa4K26QKY_4qeZaF-6F5LRqAXqkFI");
var startRow = 2;
var numRows = 1000;
var dataRange = sheet.getRange("A1:G1000")
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var module = row[4]
if(module=="Air Quality"){
var email="gooco.pm@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Water Quality"){
var email="cedino.lar@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Chemicals Management"){
var email="santiago.ce@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Wastes Management"){
var email="santiago.ce@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="EIA"){
var email="walican.nsw@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Others"){
var email="flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";
}
var requester=row[2];
var group=row[3];
var description=row[5];
var completion=row[6];
MailApp.sendEmail(email, requester, description);
}}
这是我到目前为止所做的......
希望有人可以帮助我。提前致谢
答案 0 :(得分:0)
如果此脚本是原始脚本,将发送的邮件数量为&#34; data.length&#34;由&#34; A1:G1000&#34;定义。如果您想使用&#34; module&#34;,&#34; MailApp.sendEmail()&#34;的值发送电子邮件。应该放入&#34;如果&#34;。那么这个剧本怎么样?
function emailspecialist() {
var sheet = SpreadsheetApp.openById("15Om5F29GIlu77rQa4K26QKY_4qeZaF-6F5LRqAXqkFI");
var startRow = 2;
var numRows = 1000;
var dataRange = sheet.getRange("A1:G1000")
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
if(module=="Air Quality"){
var email="gooco.pm@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Water Quality"){
var email="cedino.lar@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Chemicals Management"){
var email="santiago.ce@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Wastes Management"){
var email="santiago.ce@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="EIA"){
var email="walican.nsw@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Others"){
var email="flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else {
var email = "";
}
if (email.length > 0) {
var row = data[i];
var requester = row[2];
var group = row[3];
var module = row[4];
var description = row[5];
var completion = row[6];
MailApp.sendEmail(email, requester, description);
}
}
}
答案 1 :(得分:-1)
我正在尝试输入emailSent功能,以便不会重复已通过电子邮件发送的条目。这是我编辑的版本,在此期间无效。
function emailspecialist() {
var sheet = SpreadsheetApp.openById("16OxeGOCb7wur4k0qc0dMWbUt_tSvf4elfefZIpqWBSc");
var startRow = 2;
var numRows = 1000;
var dataRange = sheet.getRange("A1:G1000")
var data = dataRange.getValues();
var emailSent = "Email Sent";
for (var i = 0; i < data.length; ++i) {
var module = data[i][4];
if(module=="Air Quality"){
var email="gooco.pm@energy.com.ph";}
else if(module=="Water Quality"){
var email="cedino.lar@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Chemicals Management"){
var email="santiago.ce@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Wastes Management"){
var email="santiago.ce@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="EIA"){
var email="walican.ns@energy.com.ph"+","+"flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else if(module=="Others"){
var email="flores.ef@energy.com.ph"+","+"rvjpascual@energy.com.ph";}
else {
var email = "";
}
if (email.length > 0) {
var row = data[i];
var requester = row[2];
var group = row[3];
var description = row[5];
var completion = row[6];
var isEmailSent = row[7];
if (isEmailSent != emailSent) {
MailApp.sendEmail(email, requester, description);
sheet.getRange(startRow + i, 7).setValue(emailSent);
}}
}
}