Google Script SendEmail 无法发送完整消息。

huangapple go评论53阅读模式
英文:

Google Script SendEmail doesn't send complete message

问题

我使用了一个Google脚本来发送电子邮件。

以下是下面的代码。

n = 29,因此有28封电子邮件要发送。
对于每一行,“message”是从其他工作表的多个数据连接在一起的文本。

例如:

  • 对于第2行的“message”写着“Hello team A2, here is the list of non compliant items B2, C2, D2”
  • 对于第3行的“message”可能是“Hello team A3, here is the list of non compliant items B3, C3”。

我注意到,只有19行的电子邮件被正确发送(所有B、C、D项目都被正确提及,就像在ggsheet中一样),而对于9行,由于我无法解释的原因,情况并不正确。对于这9行,有时根本没有项目名称(例如,对于第2行,与上面的消息不同,我们有“Hello team A2, here is the list of non compliant items”),但有时我们只有部分名称(例如,对于第3行,与上面的消息不同,我们有“Hello team A3, here is the list of non compliant items B3”)。

你可以帮忙吗?

function sendEmail() {

var ss = SpreadsheetApp.getActiveSpreadsheet()

var sheet1 = ss.getSheetByName('TEXT');

var sheet2 = ss.getSheetByName('Sheet2');

var subject = "Critical Corso 8h"

var n = sheet1.getLastRow();

for (var i = 2; i < n + 1 ; i++ ) {

var emailAddressTL = sheet1.getRange(i,4).getValue();

var ServiceAcquired = sheet1.getRange(i,3).getValue();

var message = sheet2.getRange(2,2).getValue();

message = message.replace("<service>", ServiceAcquired);
if (emailAddressTL == "") {
  continue
}

MailApp.sendEmail(emailAddressTL, subject, message);


}

}

希望这有所帮助。

英文:

I used a google script in order to send e-mails.

Here is the code below.

n=29, so there are 28 e-mails to be sent.
For each row "message" is a text which is a concatenate of several data from other sheets.

For instance :

  • for "message" of the row 2 is written "Hello team A2, here is the list of non compliant items B2,C2,D2"
  • for "message" row 3 could be "Hello team A3, here is the list of non compliant items B3,C3"

I noticed that the e-mails are sent correctly only for 19 rows (with all the B,C,D items non compliants correctly mentioned, as in the ggsheet) whereas for 9 rows, for a reason I can't explain it's not correct. For these 9 rows sometimes there is no items name at all (example for row 2 instead of message above, we have "Hello team A2, here is the list of non compliant items") but sometimes we have only partial names (example for row3 instead of message above, we have "Hello team A3, here is the list of non compliant items B3"

Could you help ?

 function sendEmail() {

var ss = SpreadsheetApp.getActiveSpreadsheet()

var sheet1=ss.getSheetByName(&#39;TEXT&#39;);

var sheet2=ss.getSheetByName(&#39;Sheet2&#39;);

var subject = &quot;Critical Corso 8h&quot;

var n=sheet1.getLastRow();

for (var i = 2; i &lt; n+1 ; i++ ) {

var emailAddressTL = sheet1.getRange(i,4).getValue();

var ServiceAcquired=sheet1.getRange(i,3).getValue();

var message = sheet2.getRange(2,2).getValue();

message=message.replace(&quot;&lt;service&gt;&quot;,ServiceAcquired);
if (emailAddressTL == &quot;&quot;) {
  continue
}

MailApp.sendEmail(emailAddressTL, subject, message);


}

}

答案1

得分: 2

以下是代码的翻译部分:

function sendEmail() {
  var ss = SpreadsheetApp.getActive();
  var sheet1 = ss.getSheetByName('TEXT');
  var sheet2 = ss.getSheetByName('Sheet2');
  var subject = "Critical Corso 8h"
  var n = sheet1.getLastRow();
  for (var i = 2; i < n + 1; i++) {
    var emailAddressTL = sheet1.getRange(i, 4).getValue();
    var ServiceAcquired = sheet1.getRange(i, 3).getValue();
    var message = sheet2.getRange(2, 2).getValue();
    message = message.replace("<service>", ServiceAcquired);
    if (emailAddressTL != "") {
      MailApp.sendEmail(emailAddressTL, subject, message);
    }
  }
}

请提供要创建数据表格,但请删除私人信息。

英文:

Try this:

function sendEmail() {
  var ss = SpreadsheetApp.getActive();
  var sheet1 = ss.getSheetByName(&#39;TEXT&#39;);
  var sheet2 = ss.getSheetByName(&#39;Sheet2&#39;);
  var subject = &quot;Critical Corso 8h&quot;
  var n = sheet1.getLastRow();
  for (var i = 2; i &lt; n + 1; i++) {
    var emailAddressTL = sheet1.getRange(i, 4).getValue();
    var ServiceAcquired = sheet1.getRange(i, 3).getValue();
    var message = sheet2.getRange(2, 2).getValue();
    message = message.replace(&quot;&lt;service&gt;&quot;, ServiceAcquired);
    if (emailAddressTL != &quot;&quot;) {
      MailApp.sendEmail(emailAddressTL, subject, message);
    }
  }
}

Please provide a table of data but redact private info

huangapple
  • 本文由 发表于 2023年4月7日 00:55:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951974.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定