我正在用Google脚本编写代码,以便在提交Google表单时将电子邮件发送到四个不同的地址。结果是,电子邮件被发送到每个地址,但是一式两份。我的上一个试用版向每个地址发送了12封电子邮件。
我已经在Google脚本中设置了触发器,以便在提交Google表单时执行。
我尝试过将电子邮件放在分散的羊群中并循环浏览列表。
我用电子邮件地址创建了一个数组,并使用此数据创建了一个循环。
所有尝试都导致了相同的重复问题。
enter code here
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ContactInformation");
var ssStaff = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("StaffInformation");
var lastRowResponse = ss.getLastRow();Logger.log("lastRowResponse = " + lastRowResponse);
Logger.log("Get the current Date and Time"); // Title Logger.log Satament
var CurrentTimeStamp = ss.getRange("A"+lastRowResponse).getValue(); Logger.log("CurrentTimeStamp = " + CurrentTimeStamp);// Define CurrentTimeStamp as the Time Submitted
var GetDayNumber = CurrentTimeStamp.getDay();Logger.log("GetDayNumber = " + GetDayNumber);// Get the day number
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var DayName = weekday[GetDayNumber];Logger.log("DayName = " + DayName);// Get the day Name
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var day = CurrentTimeStamp.getDate();
var monthIndex = CurrentTimeStamp.getMonth();
var year = CurrentTimeStamp.getFullYear();
var FullDate = DayName + ", " + monthNames[monthIndex] + " " + day + ", " + year;Logger.log("FullDate = " + FullDate);// Get the FullDate
ss.getRange("F"+lastRowResponse).setValue("no"); Logger.log("Email1Sent = " + ss.getRange("F"+lastRowResponse).getValue());
ss.getRange("G"+lastRowResponse).setValue("no"); Logger.log("Email2Sent = " + ss.getRange("G"+lastRowResponse).getValue());
ss.getRange("H"+lastRowResponse).setValue("no"); Logger.log("Email3Sent = " + ss.getRange("H"+lastRowResponse).getValue());
ss.getRange("I"+lastRowResponse).setValue("no"); Logger.log("Email4Sent = " + ss.getRange("I"+lastRowResponse).getValue());
var Name = ss.getRange("B"+lastRowResponse).getValue(); Logger.log("Name = " + Name);// Name given on Contact Form
var Email = ss.getRange("C"+lastRowResponse).getValue(); Logger.log("Email = " + Email);// Email given on Contact Form
var Subject = ss.getRange("D"+lastRowResponse).getValue(); Logger.log("Subject = " + Subject);// Subject given on Contact Form
var EmailBody = ss.getRange("E"+lastRowResponse).getValue(); Logger.log("EmailBody = " + EmailBody);// EmailBody given on Contact Form
var OrganizerSignature = ssStaff.getRange("A2").getValue() + " and " + ssStaff.getRange("A3").getValue() + ", TEDxBlaine Organizers";
var OrganizerEmail1 = ssStaff.getRange("B2").getValue();
var OrganizerEmail2 = ssStaff.getRange("B3").getValue();
var ReasonSummaryHTML = "<html><head><style>img {width: 100%;}</style></head>"+
"<body lang=EN-US style='tab-interval:.5in'>"+
"<div class=WordSection1>"+
"<p class=MsoNormal align=center style='text-align:center'><img src='https://lh3.googleusercontent.com/rzeA4cr5onMbWoPYdKOEKXBYWXTB40Dw5lzws5I7hEZD5t0mu0DpdPTNLgNVVTUbohrMd9IHq46kl03WSai9QGO-WATFS83qEwhNdzOVrplCmGIrxUO_5kr1hHHOUZ_LjB-xSk9F5pevJk7FJSqkAgHfScuZmKZGGkXU_knjkUZZl-SgAmCQZMTxDRZTbX4MQgXU6aUyE4EZAWn-9xQHnINQ86jSIR4cYP8-BKTEwXJWoVQc-S3IM9KlhLhf6aOOUUEdRBkgX_52GphmfPxKNQexywFXFx2ZHiRIf2kdVWBRzcCzWJ3ORbVbpaLPF-xkr5JbrkpEkifkZmleZy8-sMRAqL7LJKwLlPWcfbLyGGwY183PBooo94u_ptJmkb4fqzQvg5p0d4yFzGaDOGcGnyz6UXSsfjQKgg2MmHfMvsGjDVDzgXpxv4VwM2iES0ttW94jY4xO4w4TM-3Asmsx626vertCqpYAvWaY-D_BsK11FvScFBwxpbmueFotxTIihTj7s1DCV2-ySQJQ0hMw5WXQr01K-VVSZ8SdchH4zQO7H5Q2BLDZwDeisZqUZc7ZN_zFyXNIDuJlxS4p8eWeOy_wrhobjjopYSfJLGVlKiliF6GfgUGpFKnSOjuuQh4nVYRyeR7TUE_ZMD5dhg2taGEjyHQl1yE=w1920-h691-no' style='width:50%;'><o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Thank you for your interest in <span class=SpellE><span"+
"style='color:red'>TEDx</span>Blaine. We have received the following"+
" email from you.<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'><o:p> </o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Date: "+ FullDate +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Name:<span style='mso-spacerun:yes'> </span>"+ Name +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Email: "+ Email +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Subject: "+ Subject +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'><o:p> </o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>"+ EmailBody +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><o:p> </o:p></p>"+
"<p class=MsoNormal><o:p> </o:p></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Thank you,<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>"+ OrganizerSignature +"<o:p></o:p></span></p>"+
"<p class=MsoNormal align=center style='text-align:left'><img src='https://lh3.googleusercontent.com/J0LXjs3rBzFsSUTahPNexSC6URFJfxKnLynliJ24n24VkM0eMI52YhwiHaPB78XlCAcBpc0ptTrB5IG2VEEtzdjDOfnAGvM8NDJbP8uPS40klLf8JtzOwpvqJHaNzKsVmSXOZ6o8outl5sI8SPJ8or2ciA7CHwTugThxfwgUXS_9zv6rwfyKudEGqZbnXpJ-sXp3yHenG2ivkFNBv54QDFyHOJeUoS-0yRhZXe4e7mNWTq1-fKb9UYI0zbw5dk6sUX61UlMGReHYaSbUnvsccStpzHYnZ9xlQ44Pkbtvf7B2ghf8Y0XfMbaOnWlNixxeI7Dz9ugZMbvKcPhCQnsAFHv4QBcnACWoQ4zCskbSD7SamheLd0_fa2zRzRKW8sMno8NjJN5dfDNL6PKqS3tEgl4BmFBOay-rrAn8NCovepAozBeiqLZm3oXT_3c7Bi_cN6x8nRTW82DU4y3La0NAO6UltgGniNA-mIW1GlHhTVDnIXTosvwAOAjK6sekUtzW91Nkc23sGRb113uqLRjvZFLoU3jkksxvaJggpBHeH5PyZIDnJsIQyzpGHJ-bHVEwa7mmtst_3o13vfv1zHYn2uWdru88hDMlywE_azNyRWRf24a2vI66uRgN4fDeFruOKxyCjZPW9mZd_wnxRvGxFOyC_DhOZ8w=w314-h86-no' style='width:10%;'><o:p></o:p></span></p>"+
"</div></body></html>";
var ReasonSummaryHTML2 = "<html><head><style>img {width: 100%;}</style></head>"+
"<body lang=EN-US style='tab-interval:.5in'>"+
"<div class=WordSection1>"+
"<p class=MsoNormal align=center style='text-align:center'><img src='https://lh3.googleusercontent.com/rzeA4cr5onMbWoPYdKOEKXBYWXTB40Dw5lzws5I7hEZD5t0mu0DpdPTNLgNVVTUbohrMd9IHq46kl03WSai9QGO-WATFS83qEwhNdzOVrplCmGIrxUO_5kr1hHHOUZ_LjB-xSk9F5pevJk7FJSqkAgHfScuZmKZGGkXU_knjkUZZl-SgAmCQZMTxDRZTbX4MQgXU6aUyE4EZAWn-9xQHnINQ86jSIR4cYP8-BKTEwXJWoVQc-S3IM9KlhLhf6aOOUUEdRBkgX_52GphmfPxKNQexywFXFx2ZHiRIf2kdVWBRzcCzWJ3ORbVbpaLPF-xkr5JbrkpEkifkZmleZy8-sMRAqL7LJKwLlPWcfbLyGGwY183PBooo94u_ptJmkb4fqzQvg5p0d4yFzGaDOGcGnyz6UXSsfjQKgg2MmHfMvsGjDVDzgXpxv4VwM2iES0ttW94jY4xO4w4TM-3Asmsx626vertCqpYAvWaY-D_BsK11FvScFBwxpbmueFotxTIihTj7s1DCV2-ySQJQ0hMw5WXQr01K-VVSZ8SdchH4zQO7H5Q2BLDZwDeisZqUZc7ZN_zFyXNIDuJlxS4p8eWeOy_wrhobjjopYSfJLGVlKiliF6GfgUGpFKnSOjuuQh4nVYRyeR7TUE_ZMD5dhg2taGEjyHQl1yE=w1920-h691-no' style='width:50%;'><o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'><o:p> </o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Date: "+ FullDate +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Name:<span style='mso-spacerun:yes'> </span>"+ Name +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Email: "+ Email +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Subject: "+ Subject +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'><o:p> </o:p></span></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>"+ EmailBody +"<o:p></o:p></span></p>"+
"<p class=MsoNormal><o:p> </o:p></p>"+
"<p class=MsoNormal><o:p> </o:p></p>"+
"<p class=MsoNormal><span style='font-size:12.0pt;line-height:107%;font-family:"+
"Helvetica'>Thank you,<o:p></o:p></span></p>"+
"<p class=MsoNormal align=center style='text-align:left'><img src='https://lh3.googleusercontent.com/J0LXjs3rBzFsSUTahPNexSC6URFJfxKnLynliJ24n24VkM0eMI52YhwiHaPB78XlCAcBpc0ptTrB5IG2VEEtzdjDOfnAGvM8NDJbP8uPS40klLf8JtzOwpvqJHaNzKsVmSXOZ6o8outl5sI8SPJ8or2ciA7CHwTugThxfwgUXS_9zv6rwfyKudEGqZbnXpJ-sXp3yHenG2ivkFNBv54QDFyHOJeUoS-0yRhZXe4e7mNWTq1-fKb9UYI0zbw5dk6sUX61UlMGReHYaSbUnvsccStpzHYnZ9xlQ44Pkbtvf7B2ghf8Y0XfMbaOnWlNixxeI7Dz9ugZMbvKcPhCQnsAFHv4QBcnACWoQ4zCskbSD7SamheLd0_fa2zRzRKW8sMno8NjJN5dfDNL6PKqS3tEgl4BmFBOay-rrAn8NCovepAozBeiqLZm3oXT_3c7Bi_cN6x8nRTW82DU4y3La0NAO6UltgGniNA-mIW1GlHhTVDnIXTosvwAOAjK6sekUtzW91Nkc23sGRb113uqLRjvZFLoU3jkksxvaJggpBHeH5PyZIDnJsIQyzpGHJ-bHVEwa7mmtst_3o13vfv1zHYn2uWdru88hDMlywE_azNyRWRf24a2vI66uRgN4fDeFruOKxyCjZPW9mZd_wnxRvGxFOyC_DhOZ8w=w314-h86-no' style='width:10%;'><o:p></o:p></span></p>"+
"</div></body></html>";
MailApp.sendEmail(Email, Subject, "--", {'noReply':true, 'htmlBody': ReasonSummaryHTML});
MailApp.sendEmail("TEDxBlaine@Gmail.Com", Subject, "--", {'noReply':true, 'htmlBody': ReasonSummaryHTML2});
MailApp.sendEmail(OrganizerEmail1, Subject, "--", {'noReply':true, 'htmlBody': ReasonSummaryHTML2});
MailApp.sendEmail(OrganizerEmail2, Subject, "--", {'noReply':true, 'htmlBody': ReasonSummaryHTML2});
我希望每个电子邮件地址在Google表单上每次提交时都会收到一封电子邮件。