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