我有一个Apps脚本可以自动处理一些电子邮件,并希望从模板发送正文。我认为我可以将模板存储为google doc,然后将其发送到脚本中。我有这样的东西:
var doc = DocumentApp.openById(“ DocumentID”);
MailApp.sendEmail(“ toEmail”, “ fromEmail”, “ TPS报告状态”, doc.getBody()。getText());
这确实有效,除了电子邮件正文在看起来随机的区域中插入了新行外,尽管它确实保留了原始文档中的新段落。它在图像中不那么明显,但是红色圆圈是应该换行的东西的换行符。通过gmail应用程序查看时非常明显。
答案 0 :(得分:1)
您实际上需要以html格式设置正文文本的格式,然后可以使用带有'htmlBody'参数的mailapp用户来传递正文。
您需要获取正文的段落,并添加一个for循环,并在每个段落的开头添加
标记。
function getBody()
{
try{
var para=tempDoc.getBody().getParagraphs();
var body=''
for(var y=0;y<para.length;y++)
{
body+="<br>"+para[y].getText();
}
return body;
}
catch(ex)
{
Logger.log(ex)
}
}
答案 1 :(得分:0)
要添加到上述答案中,您的html正文应如下所示:
body = "Good day, \n\nThe following course has been loaded for deployment:" + "\nCourse Name: " + courseName + "\nCourse Type ID: " + courseID + "\nContent Version: " + courseVersion +
"\nCourse Language: " + courseLanguage + "\n\nCourse Filename: " + title + "\nCourse File Location: " + fileLocation + "\nCourse Filesize: " + fileSize +
"\nDeployment Required By: " + deploymentDate + "\nCourse Live Date: " + courseLiveDate + "\n\n Kind regards\n Department Name";
MailApp.sendEmail(recipient, subject, body, {cc: carbonCopy, noReply: true});