[英]Sending email via GmailApp as HTML to retain signature & image
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.我有一个项目,我需要批量发送一封电子邮件,其中包含特定于每个用户的文本,以及来自关联 gmail 帐户的签名和图像。 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("me@me.com", "test", scGmailContactMessageBody);
Issue is the resultant email is just the raw html with the image displayed at the bottom问题是生成的电子邮件只是原始 html,图像显示在底部
I've tried adding {htmlBody: html}
as an option but that throws an error html not defined
.我尝试添加
{htmlBody: html}
作为选项,但这会引发错误html not defined
。
Any help would be much appreciated任何帮助将非常感激
The htmlBody
expects a string. htmlBody
需要一个字符串。
GmailApp.sendEmail("me@me.com", "test", scGmailContactMessageBody, {htmlBody: scGmailContactMessageBody});
No need for let bodyHtml = HtmlService.createHtmlOutput(scGmailContactMessageBody);
不需要
let bodyHtml = HtmlService.createHtmlOutput(scGmailContactMessageBody);
as getBody()
already returns an HTML string.因为
getBody()
已经返回一个 HTML 字符串。
From the question从问题
I've tried adding
{htmlBody: html}
as an option but that throws an errorhtml
not defined.我试过添加
{htmlBody: html}
作为一个选项,但这会引发一个错误html
未定义。
The error message is straight forward, the code doesn't include an statement declaring html
错误消息很简单,代码不包含声明
html
的语句
try replacing html
by bodyHtml
尝试用
bodyHtml
替换html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.