简体   繁体   English

如何使用电子表格中的 Google App 脚本生成 Gmail 草案包含正文中的表格

[英]How to Generate Gmail draft using Google App Script from Spreadsheet contains Table in the Body

I want to Generate a Gmail draft using Google App Script from Spreadsheet contains Table in the Body.我想使用电子表格中的 Google App 脚本生成 Gmail 草稿,其中包含正文中的表格。

Below is the Screenshot of what input values I have and what type of output I want.下面是我有什么输入值和我想要什么类型的 output 的屏幕截图。

I shall be thankful if you could share the complete GS code, as I m new at Google App Scripts.如果您能分享完整的 GS 代码,我将不胜感激,因为我是 Google App Scripts 的新手。

In Addition, I also want a Signature in the email Body, "Thanks and Regards" is my part of the body.此外,我还想在 email 正文中签名,“Thanks and Regards”是我正文的一部分。

Also please note that Column E is dynamic, means may b it has 1 row and may be more than 1.另请注意,E 列是动态的,意味着它可能有 1 行并且可能超过 1。

currently I am using this code.目前我正在使用此代码。

 function Email_Loop_BL() { const signature = Gmail.Users.Settings.SendAs.list("me").sendAs.filter(function(account){if(account.isDefault){return true}})[0].signature; var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getActiveSheet(); var index = 2; var index1 = 2; var lastRow = sheet.getLastRow(); var data = sheet.getRange(1, 5, 10).getValues(); Logger.log(data) for (;index1 <= data; index1++){ var message2 = sheet.getRange(index, 5, 1, 1).getValue(); } 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(); //var location = sheet.getRange(index, 5, 1, 1).getValue(); //var guests = sheet.getRange(index, 6, 1, 1).getValue(); //var eventColour = sheet.getRange(index, 7, 1, 1).getValue(); //var sendInvites = true; const html = "<div> </div><br>" + signature; const options = { htmlBody: message + data + html, cc: ccmail } GmailApp.createDraft(emailAddress, subject, '', options); }// End of Function

输入

this is my input这是我的输入

这是我想要的输出。

this is my output I want.这是我想要的 output。

function sendemail() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('Sheet1');
  const rg=sh.getDataRange();
  const vs=rg.getDisplayValues();
  GmailApp.createDraft(vs[1][0].toString().split(/\n/).join(','),vs[1][2],'',{htmlBody:vs[1][3].toString().split(/\n/).join('<br>') + '<br>' + vs[1][4].toString().split(/\n/).join('<br>') + '<br>' + vs[1][5],cc:vs[1][1].toString().split(/\n/).join(',')});
}

My Data in Sheet1:我在 Sheet1 中的数据:

在此处输入图像描述

The Draft:草案:

在此处输入图像描述

You can add more emails to recipients and cc by putting them on separate lines within the cell but terminating each line with a ctrl enter .您可以将更多电子邮件添加到收件人和抄送,方法是将它们放在单元格内的单独行中,但以ctrl enter终止每一行。 Same is true with the invoices.发票也是如此。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Google脚本将Google电子表格表格复制粘贴到gmail中? - How to copy paste a google spreadsheet table into gmail using google script? 如何使用应用脚本从 Gmail CSV 附件中提取特定列到 Google 电子表格? - How to pull specific columns from Gmail CSV attachment to Google Spreadsheet using app script? 使用Google Appscript - 如何使用位于Gmail中的草稿模板中的自定义正文发送自动电子邮件? - With Google Appscript - How to send a automated email using a custom body from a draft template located in Gmail? 无法使用谷歌应用脚本从 gmail 正文中提取 substring - unable to extract substring from gmail body using google app script 通过谷歌脚本将表格从 gmail 插入谷歌电子表格 - Insert table from gmail to google spreadsheet by google script 如何共享包含Google App脚本的Google电子表格? - How to share a google spreadsheet that contains google app script? 如何使用Google App脚本在Google驱动器中的特定文件夹中生成Google电子表格的JSON? - how to generate json of google spreadsheet at specific folder in google drive using google app script? 使用 GmailApp 从 Google App 脚本创建 HTML 草稿 - Create HTML Draft from Google App script using GmailApp 使用谷歌应用脚本从 gmail 正文匹配 url 时出错 - error when matching url from gmail body using google app script Gmail应用程序脚本从电子表格添加密件抄送 - Gmail App Script Add BCC from Spreadsheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM