[英]Create HTML Draft from Google App script using GmailApp
I want to create a Google App Script to get Gmail Draft with a signature, by collecting data from a google spreadsheet.我想创建一个谷歌应用程序脚本,通过从谷歌电子表格收集数据来获取带有签名的 Gmail 草案。 by default,默认,
function Loop_Email_Drafts() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getActiveSheet(); var index = 2; var lastRow = sheet.getLastRow(); for (;index <= lastRow; index++){ var emailAddress = sheet.getRange(index, 1, 1, 1).getValue(); var ccmail = sheet.getRange(index, 2, 1, 1).getValue(); var subject = sheet.getRange(index, 3, 1, 1).getValue(); var message = sheet.getRange(index, 4, 1, 1).getValue(); GmailApp.createDraft(emailAddress, subject, message, {cc: ccmail}); }// End of For Loop }// End of Function
google app script is creating a plain text draft from which I cant add my signature(my signature also contains an image).谷歌应用程序脚本正在创建一个纯文本草稿,我无法从中添加我的签名(我的签名还包含图像)。
Currently, I m using the below code to generate a draft but without a signature is worthless.目前,我正在使用以下代码生成草稿,但没有签名是毫无价值的。
If you just want to add an HTML body to the draft, you can use the following method:如果只想在草稿中添加一个 HTML 主体,可以使用以下方法:
Where options
refers to an object that can contain a series of advanced parameters, including:其中options
是指一个 object 可以包含一系列高级参数,包括:
- htmlBody : if set, devices capable of rendering HTML will use it instead of the required body argument; htmlBody :如果设置,能够呈现 HTML 的设备将使用它而不是所需的 body 参数; you can add an optional inlineImages field in HTML body if you have inlined images for your email如果您的 email 有内联图像,您可以在 HTML 正文中添加一个可选的 inlineImages 字段
- inlineImages : a JavaScript object containing a mapping from image key (
String
) to image data ( BlobSource ); inlineImages :一个 JavaScript object 包含从图像键(String
)到图像数据( BlobSource )的映射; this assumes that thehtmlBody
parameter is used and contains references to these images in the format <img src="cid:imageKey" />这假定使用了htmlBody
参数并包含对这些图像的引用,格式为<img src="cid:imageKey" />
That is, you define the image you want in inlineImages
and add them to your HTML using the corresponding imageKey
.也就是说,您在inlineImages
中定义所需的图像,并使用相应的 imageKey 将它们添加到imageKey
中。 Here's an example of how this could be done:这是一个如何做到这一点的示例:
const html = "<p>Whatever</p><img src=\"cid:yourImageKey\" />";
const options = {
htmlBody: html,
inlineImages: {
yourImageKey: YOUR_IMAGE_BLOBSOURCE
}
}
GmailApp.createDraft(recipient, subject, '', options);
You can actually manage signatures via Gmail API, and therefore with Apps Script (using the Advanced Gmail Service ).您实际上可以通过 Gmail API 管理签名,因此可以使用 Apps 脚本(使用高级 Gmail 服务)。
In order to add your actual signature to your draft, you can do the following:为了将您的实际签名添加到草稿中,您可以执行以下操作:
htmlBody
.将此签名添加到您的htmlBody
。const signature = Gmail.Users.Settings.SendAs
.get("me", "email_address_or_alias")
.signature;
const html = "<div>YOUR_HTML_BODY</div><br>" + signature;
const options = {
htmlBody: html,
cc: ccmail
}
GmailApp.createDraft(recipient, subject, '', options);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.