I am using the script to send the bithday email and here is my script.
/**
* @OnlyCurrentDoc
*/
function sendMails() {
var wrkBook = SpreadsheetApp.getActiveSpreadsheet();
var employeeEmail = wrkBook.getSheetByName("Wish");
var employeeCount = employeeEmail.getLastRow();
var employeeList = employeeEmail.getRange(2,1,employeeCount,12).getValues();
var day = new Date();
var currentDate = Utilities.formatDate(day,SpreadsheetApp.getActive().getSpreadsheetTimeZone(),"yyyy-M-d")
var year = Utilities.formatDate(day,SpreadsheetApp.getActive().getSpreadsheetTimeZone(),"yyyy")
var name = "";
var emailAddress = "";
var ccEmail = "";
var bccEmail = "";
var imageURL = "";
var signature = "";
var message = "";
var borderColor = "#000000";
var backgroundColor = "#ffffff";
var textColor = "#000000";
for (var i=0;i<employeeList.length;++i){
if (currentDate == year + "-" + employeeList[i][2]+"-"+employeeList[i][1]){
var htmlContent = HtmlService.createHtmlOutputFromFile('view').getContent();
var name = employeeList[i][0];
var emailAddress = employeeList[i][3];
var ccEmail = employeeList[i][4];
var bccEmail = employeeList[i][5];
var imageURL = employeeList[i][6];
var signature = employeeList[i][7];
var message = employeeList[i][8];
//style
// htmlContent = htmlContent.replace("border_color", borderColor);
// htmlContent = htmlContent.replace("background_color", backgroundColor);
// htmlContent = htmlContent.replace("text_color", textColor);
//content
htmlContent = htmlContent.replace("Employee_Name", name);
htmlContent = htmlContent.replace("Dynamic_Message", message);
htmlContent = htmlContent.replace("download", imageURL);
htmlContent = htmlContent.replace("Dynamic_Signature", signature);
//breakline
htmlContent = htmlContent.replace("<br>", "\n");
//Send out email
MailApp.sendEmail(
emailAddress,
"Happy Birthday " + name,
htmlContent,{
cc:ccEmail,
bcc: bccEmail,
htmlBody: htmlContent,
}
);
}
}
}
view.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<table style="border:2px solid border_color; background-color: background_color; color: text_color;" width=750px>
<tr>
<p style="font-family: 'Freehand', cursive; font-size: 36px;"> Dear Employee_Name</p><br><br>
</tr>
<tr>
<p style="font-family: 'Roboto Slab', serif; font-size: 36px;"> Dynamic_Message </p><br>
</tr>
<tr>
<img src="https://drive.google.com/uc?export=view&id=download" width="750" height="750" alt="" />
</tr>
<tr>
<p style="white-space: pre-line">
<p align=left, style="font-family: 'Pacifico', cursive; font-size: 36px;">Dynamic_Signature </p>
</p>
<br>
</tr>
</table>
</body>
</html>
google sheet table
However when I run this script with end up receive the email with crashed image
is there any solution to solve this? and also how should I change the code if I want to send the image with inline image instead of using this way.