【问题标题】:Sending email via GmailApp as HTML to retain signature & image通过 GmailApp 以 HTML 格式发送电子邮件以保留签名和图像
【发布时间】:2020-09-17 03:39:36
【问题描述】:

我有一个项目,我需要批量发送一封电子邮件,其中包含特定于每个用户的文本,以及来自关联 gmail 帐户的签名和图像。我有这个自动取款机:

//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);

问题是生成的电子邮件只是原始 html,图像显示在底部

我尝试添加{htmlBody: html} 作为选项,但会引发错误html not defined

任何帮助将不胜感激

【问题讨论】:

    标签: javascript google-apps-script


    【解决方案1】:

    htmlBody 需要一个字符串。

    GmailApp.sendEmail("me@me.com", "test", scGmailContactMessageBody, {htmlBody: scGmailContactMessageBody});
    

    不需要let bodyHtml = HtmlService.createHtmlOutput(scGmailContactMessageBody);,因为getBody() 已经返回了一个HTML 字符串。

    【讨论】:

    • 谢谢,我认为这是关键。设置{htmlBody: scGmailContactMessageBody}一切正常
    【解决方案2】:

    问题

    我尝试添加 {htmlBody: html} 作为选项,但会引发错误 html not defined。

    错误信息很简单,代码不包含声明html的语句

    尝试将html 替换为bodyHtml

    【讨论】:

      猜你喜欢
      • 2021-08-29
      • 2010-11-26
      • 2014-06-22
      • 2015-03-12
      • 1970-01-01
      • 2015-08-04
      相关资源
      最近更新 更多