Это код, который у меня есть, и он отлично работает! Я просто хочу знать, как изменить текст на жирный и добавить изображения, если это возможно. Для тех, где он говорит, растет, светится, по поводу. Я бы хотел, чтобы это было выделено жирным шрифтом, например.
function sendEmails() {
var allData,counter,emailAddress,fourRowsOfData,i,lastRow,
message,messageStart,messageEnd,numRows,
row,sheet,startRow,studentName,subject;
//USER INPUT
startRow = 2; // First row of data to process
numRows = 4; // Number of rows to process
subject = "Camp Pursuit: Report Card ";
messageStart = "Dear Parents,"+'\n' +'\n' +
"Every week at Camp Pursuit, we ask the teachers to make observations about how the kiddos did." +'\n' +
"We know that one week isn't enough to truly know a child, so we call this our " +"Glows, Grows, & Apropos." +'\n' +
"Meaning..." + '\n' +'\n' +
"Glows: Positive things the teacher noticed" +'\n' +
"Grows: Areas for continued growth" +'\n' +
"Apropos: Ways to continue your son/daughter enrichment" +'\n' +
"We hope you appreciate seeing what the teachers saw last week, and perhaps you can use some of"+'\n' +
"the recommendations for further enrichment this summer. Feel free to let us know your thoughts on the camp through our anonymous online survey."+'\n' +
"Your feedback helps us improve the experience for all kiddos! "+'\n' +
"Survey Link: https://docs.google.com/forms/d/1g4LvA9a8sdKECr1yvp5uOoPnvKACFm3HvbTBfvQGRyo/viewform?usp=send_form" +'\n' +
"We look forward to seeing your child at our programs throughout the year!" +'\n' +
"Sincerely, "+'\n' +
"The Camp Pursuit Team"
+'\n';
//END USER INPUT
sheet = SpreadsheetApp.getActiveSheet();
lastRow = sheet.getLastRow();
allData = sheet.getRange(startRow, 1, lastRow-startRow, 10);// Get All data first
counter = 0;
while (counter < lastRow-startRow) {
Logger.log('counter: ' + counter)
fourRowsOfData = sheet.getRange(startRow + counter, 1, numRows, 6).getValues();
emailAddress = fourRowsOfData[0][0]; // First column of first row
Logger.log('emailAddress: ' + emailAddress)
studentName = fourRowsOfData[0][1];
messageEnd = "";//Reset on every outer loop
for (i = 0; i < numRows; i++) {//loop numRows times - once for each row
row = fourRowsOfData[i];
messageEnd = messageEnd + '\n' +
"Class: " + row[2] + '\n' +'\n' +
"Glows: " + row[3]+ '\n' +
"Grows: " + row[4] +'\n' +
"Apropos: " + row[5] +'\n';
}
message = messageStart + "\n" + studentName + "\n" + messageEnd;
MailApp.sendEmail(emailAddress, subject, message);//Send the email outside of inner loop
counter+=numRows;//Increment counter by number of rows to process
}
}
В соответствии с официальной документацией MailApp
для отправки тела HTML вам нужно будет использовать параметр htmlBody
в MailApp.sendEmail()
. Взгляните на приведенный ниже пример (скопированный с официальной страницы документации)
Чтобы сделать текст полужирным, используйте <b></b>
Например: " Этот текст будет выделен жирным шрифтом.
Чтобы показать изображение по электронной почте, используйте <img src="hostname.com/image.png">
MailApp.sendEmail({
to: "[email protected]",
subject: "Logos",
htmlBody: "inline Google Logo<img src='URL_PATH'> images! <br>" +
"inline YouTube Logo <img src='URL_PATH'><br>" +
"<b>Using bold tag</b> ",
inlineImages:
{
googleLogo: googleLogoBlob,
youtubeLogo: youtubeLogoBlob
}
});
Надеюсь это поможет.
Используйте стандартные теги html в строке сообщения, затем передайте пустую строку "" или "null" в качестве параметра body в методе sendEmail(). Наконец, присвойте вашей строке сообщения свойству "htmlBody" параметра "options". Используйте теги "br" для разрывов строк. пример
function sendEmail() {
var body = "<b>Hello </b> world. <i><Hello /i> world. <br /> New line";
MailApp.sendEmail("[email protected]", "test", "", {htmlBody: body});
}
См. Раздел "Дополнительные параметры" здесь https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String.Object)