1

我创建了一个脚本,该脚本会自动发送电子邮件,从多个单元格中提取信息,并将信息与标准正文一起填充到电子邮件正文中。

但是,我无法想出一种在行之间的段落空间中编写脚本的方法。我已经完成了创建一个变量的解决方法,该变量的单元格的值只是一个段落空间,但是由于其他人将使用此电子表格,我担心该单元格会被删除并且格式会改变。

是否有另一种方法可以将段落格式化为电子邮件正文?

如果有帮助,请参阅下面的代码!我需要格式化的变量是“Var Message”

function sendEmails() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; 
  var numRows = 99;  
  var dataRange = sheet.getRange(startRow, 1, numRows, 16)
  var data = dataRange.getValues();

for (var i = 0; i < data.length; ++i) {
  var EMAIL_SENT = "Contacted";
  var currentdate = Utilities.formatDate(sheet.getRange("n2").getValue(), "GMT" , "dd/MM/yyyy" );
  var staffmember = sheet.getRange("o2").getValue();
  var paragraph = sheet.getRange("f2").getValue(); 
  var row = data[i];
  var emailAddress = row[0];  
  var name = row[1];
  var company = row[2];
  var website = row[3];
  var role = row[4];
  var show = row[9];
  var date = Utilities.formatDate(row[15], "GMT" , "dd/MM/yyyy" );
  var date2 = Utilities.formatDate(row[15], "GMT" , "dd/MM" );
  var time = Utilities.formatDate(row[11], "GMT" , "HH:mm" );
  var message = "Hello," + paragraph + "Could you please authorise or decline the following Arts Industry comp request from the Fringe Office? If you could reply within 72 hours, that would be great:" + paragraph + name + "  " + company + "  " + website + "  " + role + paragraph + show + "  " + date + "  " + time + paragraph + "Many thanks," + paragraph + staffmember ;
  var subject = "ARTS INDUSTRY REQUEST";
  var emailSent = row[12];

if (emailSent != EMAIL_SENT) {
  if (date > currentdate) {
  var subject = "ARTS INDUSTRY REQUEST";
  MailApp.sendEmail(emailAddress, subject, message);
  sheet.getRange(startRow + i, 13).setValue(EMAIL_SENT);
  SpreadsheetApp.flush();
    }

 else if (emailSent != EMAIL_SENT) {
  if (date < currentdate) {
  var subject2 = "URGENT: ARTS INDUSTRY REQUEST" + " " + date2;
  MailApp.sendEmail(emailAddress, subject2, message);
  sheet.getRange(startRow + i, 13).setValue(EMAIL_SENT);
  SpreadsheetApp.flush();
     }    
    }  
   }
  }
 }
4

2 回答 2

2

对于纯文本电子邮件,您可以使用“换行符”转义序列\n

如果您有 K&R “ C - 编程语言”,您将在第 2 章中找到完整的转义序列列表。在线参考可在此处获得。

var message = "Hello,\n"
            + "Could you please authorise or decline the following Arts Industry comp request from the Fringe Office? If you could reply within 72 hours, that would be great:\n\n" 
            + name + "  " + company + "  " + website + "  " + role
            + '\n' + show + "  " + date + "  " + time
            + '\n\n'
            + "Many thanks,"
            + '\n\n'
            + staffmember ;
于 2013-09-17T18:04:16.337 回答
1

您可以使用MailApp.sendEmail()功能的高级选项更有效地实现段落和换行符。这是一个例子

var content = "Here is some text <br> " + 
   "that is split over two lines" ; 
MailApp.sendEmail(recipient, subject, '',{'htmlBody' : content } );
于 2013-09-17T17:21:09.387 回答