gpt4 book ai didi

javascript - MailApp.sendEmail l 不再工作(谷歌应用程序脚本)

转载 作者:行者123 更新时间:2023-12-03 05:17:27 25 4
gpt4 key购买 nike

我制作了一个绑定(bind)脚本来扫描其电子表格的记录,如果某些条件成立,则会将电子邮件发送给相应的员工

更具体地说,该脚本是通过一列检查员工列表是否有生日,而不是 true 或 false 值。我的脚本运行了几周,今天它停止发送电子邮件,没有更改任何内容

我的代码

function send() {

//returns the current active spreadsheet
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();


var recipient;
var startRow = 2; // First row of data to process
var lastRow = sheet.getLastRow();//Last row to process ,the EOF
var emailSend = "FALSE";//flag to know if the mail has been sent
var d = new Date();//saving the date
var timeStamp = d.getYear();//specifing the years section



//take images location
var wishes_imageURL ="http://dekhnews.com/wp-content/uploads/... nielsen_imageURL="http://www.nielsen.com/content/dam/nielsenglobal/us

//change them to objects blobs
var wishesBlob = UrlFetchApp
.fetch(wishes_imageURL)
.getBlob()
.setName("wishesBlob");
var nielsenBlob = UrlFetchApp
.fetch(nielsen_imageURL)
.getBlob()
.setName("nielsenBlob");


//for every employee that the 4rth column is true(has_birthday) send email to his/her email address
for (var i =startRow ; i <= lastRow; i++) {

//take info about if the birthday mail has been send before to the employee
emailSend = sheet.getRange(i, 6).getValue();

//whoever has birthday and havent get email before send him/her mail
if( ( sheet.getRange(i, 5).getValue() == true) && (emailSend !="TRUE") && ( timeStamp == sheet.getRange(1, 7).getValue())){

recipient = sheet.getRange(i, 4).getValue();
MailApp.sendEmail(sheet.getRange(i, 4).getValue(),
"",
"BirthDay Wishes",

{ htmlBody:"<h3 style='text-align:center; color:blue;'><i>" + "Για τα γενέθλιά σου ευχόμαστε ολόψυχα Χρόνια Πολλά και κάθε προσωπική και επαγγελματική επιτυχία!" +
"</i></h3>" + "<center><img src='cid:wishes' style='width:500px; height:450px; align:center; position:relative; '/></center>" + "\n" +
"<h3 style = 'text-align:center;color:blue;'>" + "Βίκη – Σπύρος &" +"\n" + "Δ/νση Ανθρώπινου Δυναμικού" + "</h3>" + "\n"
+ "\n\n\n\n"+ "<center><img src='cid:nielsen'/></center>",
inlineImages:
{
wishes: wishesBlob,
nielsen: nielsenBlob
}
});


//after we sent the mail we "lock" this emplyee for the current year
sheet.getRange(i,6).setValue("TRUE");
}
}

我检查了执行记录,它没有显示是否发送了电子邮件。但是如果我使用这样的东西,它就可以工作

MailApp.sendEmail("recipient.address@gmail.com", // to
"sender.name@gmail.com", // from
"Your Subject Goes Here", // email subject
"What ever you want to say"); // email body

你能帮我吗..?先谢谢了

最佳答案

首先,如果您确定您的脚本中没有任何更改,我将确保您的电子表格中没有任何更改。如果是这种情况,其次我将确保您的 timestamp 变量仍然有效,因为这是新的一年。除此之外,一些调试技巧是:

由于您的第二个代码块有效,但原始代码块无效,因此我将逐步从不适用于示例的 sendEmail 函数中一次替换一个参数。这样您就可以将范围缩小到失败的特定参数。

我猜它要么是“to”参数,您可能会从电子表格中获取错误的字段,要么是“电子邮件正文”,您可能会在其中获取错误的字段。获取您的图像,网址可能会发生变化等。

关于javascript - MailApp.sendEmail l 不再工作(谷歌应用程序脚本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41550506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com