简体   繁体   English

通过 GmailApp 作为 HTML 发送电子邮件以保留签名和图像

[英]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 error html 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.

相关问题 通过电子邮件发送生成的Highchart图片 - Sending Generated Highchart image via email 每个电子邮件收件人的 GmailApp 配额或如何在不向 50 多人发送电子邮件的情况下测试 GmailApp 代码? - GmailApp per email recipient quota or how can I test GmailApp code without sending an email to 50+ people? 通过GmailApp.sendEmail在html电子邮件正文中使用电子表格值 - Using spreadsheet values in html body of email with GmailApp.sendEmail GmailApp提取电子邮件 - GmailApp fetching email 使用 PHPMailer 和 html2pdf 通过 email 发送 PDF 数据 - Sending PDF data via email using PHPMailer and html2pdf 通过python脚本发送包含javascript的动态html电子邮件 - sending dynamic html email containing javascript via a python script 通过调用.aspx.vb从.html页面发送电子邮件 - Sending An Email From a .html Page via Calling A .aspx.vb 验证电子邮件地址,然后再通过带有Ajax的html表单发送电子邮件地址 - Verify email address before sending it via html form with ajax 通过phonegap中的电子邮件发送存储在html5 localStorage中的信息 - Sending information stored in html5 localStorage via email in phonegap 发送 HTML 电子邮件时图像中断,文本上有图像 - Image break in sending HTML email with text over image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM