Reputation: 601
I have a project where i need to bulk send an email with text specific to each user, and with the signature and image from the associated gmail account. I've got this atm:
//get template/draft email & body
const scGmailTemplate = GmailApp.getDraft("r4329894329375089160");
const scGmailTemplateMessage = scGmailTemplate.getMessage();
const scGmailTemplateBody = scGmailTemplateMessage.getBody();
//create new gmail
let scGmailContactMessageBody = scGmailTemplateBody;
//create array for gmail find & replaces [find, replace]
const gmailFindReplace = [["INV_START", scVars.INV_START],
["INV_END", scVars.INV_END],
["DEM_DATE", scVars.DEM_DATE]
];
gmailFindReplace.forEach(x=>{scGmailContactMessageBody=scGmailContactMessageBody.replace(x[0], x[1])});
const scGmailSubject = "Service Charge Invoice ("+scVars.INV_START+"-"+scVars.INV_END+")";
let bodyHtml = HtmlService.createHtmlOutput(scGmailContactMessageBody);//didnt work
GmailApp.sendEmail("[email protected]", "test", scGmailContactMessageBody);
Issue is the resultant email is just the raw html with the image displayed at the bottom
I've tried adding {htmlBody: html}
as an option but that throws an error html not defined
.
Any help would be much appreciated
Upvotes: 0
Views: 77
Reputation: 9571
The htmlBody
expects a string.
GmailApp.sendEmail("[email protected]", "test", scGmailContactMessageBody, {htmlBody: scGmailContactMessageBody});
No need for let bodyHtml = HtmlService.createHtmlOutput(scGmailContactMessageBody);
as getBody()
already returns an HTML string.
Upvotes: 2
Reputation: 38296
From the question
I've tried adding
{htmlBody: html}
as an option but that throws an errorhtml
not defined.
The error message is straight forward, the code doesn't include an statement declaring html
try replacing html
by bodyHtml
Upvotes: 1