我的邮件脚本工作得很好但是当我尝试附加PDF时,整个世界都崩溃了。我收到错误“我们很抱歉,发生了服务器错误。请稍等一下再试一次”。
我也尝试了附件功能的各种迭代,每个都失败了。包括blob,文件,得到我的和喜欢(此时我已经变成了人类blob自己大声笑)。
请看一下这个功能。我真诚地希望有人可以帮助解决这个问题。有问题的部分是代码的最后5行(附件功能)。
我必须指出,虽然我们社区的各位成员帮助我建立了这个。感谢您的期待
function welcome(){
var hour = new Date().getHours();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var length = sheets.length;
for( var i=0; i < length; i++) {
var sheet = ss.getSheets()[i];
var sheetName = sheet.getName()
const emailAddress = "marketing@theperch.in";
const subject = "Bookingmail Script not executed"
const message = "Please check script and run again"
if(sheetName != "name of sheet to be excluded"){
bookingmail(sheet)
}}
}
function bookingmail(sheet) {
var startRow = 2; // First row of data to process
var numRows = sheet.getLastRow()
var lastCol = sheet.getLastColumn() // Number of rows and coloumns to
process
var EMAIL_SENT = "EMAIL_SENT"; // This constant is written in column V for
rows for which an email
var dataRange = sheet.getRange(startRow, 1, numRows, lastCol) // Fetch
values for each row in the Range
var message = sheet.getRange("W2").getValue(); // This is for cell W2
var data = dataRange.getValues();
// Loop created to fulfill the if conditions and then execute mailsend app
for (var i = 0; i <= numRows - 1; i++) {
var row = data[i];
var emailAddress = row[8]; // Ninth column
var emailSent = row[21]; // Twenty second column
var daysleft = row[20]; // Twenty first coloumn
var subject = "Your upcoming stay; Helpful Information "; // E-Mail Subject
var file = DriveApp.getFileById('0B3R47ecEHS2-WUFRTmFaT2piWDg');
//I have added a condition to make sure that it will only send if the
customer has not already received an email
if (emailSent != EMAIL_SENT && emailAddress != '' && (daysleft === 0 ||
daysleft === 1)) { // Prevents sending sending same mail again to a person,
also
skips blank cells
//if
daysleft =1 or 0 then send mail .
MailApp.sendEmail(emailAddress, subject, message, {
attachments: [file.getAs(MimeType.PDF), blob],
name: 'Welcome mail- Perch Arbor Golf Course.pdf'});
sheet.getRange(startRow + i, 22).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is
interrupted
}
}
SpreadsheetApp.flush();//you only need to do this when all the rows have
been processed
}