简体   繁体   中英

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.

Below is the Screenshot of what input values I have and what type of output I want.

I shall be thankful if you could share the complete GS code, as I m new at Google App Scripts.

In Addition, I also want a Signature in the email Body, "Thanks and Regards" is my part of the body.

Also please note that Column E is dynamic, means may b it has 1 row and may be more than 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.

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:

在此处输入图像描述

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 . Same is true with the invoices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM