例外:参数(字符串、字符串、字符串、(类)、(类))与 GmailApp.sendEmail 的方法签名不匹配



我正试图找出解决我的错误的方法,如对象中所述。出了问题

GmailApp.sendEmail.

顺便说一句,我是GAS编码的新手,如果你认为脚本可以增强,请放心。

function emailAsPDF() {
SpreadsheetApp.flush();
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheetByName("Recherche"));
var sheet = ss.getActiveSheet();
var gid = sheet.getSheetId();
var pdfOpts = 
+ // export as pdf
'&size=0' + // paper size letter / You can use A4 or legal
'&portrait=false' + // orientation portal, use false for landscape
'&fitw=true' + // fit to page width false, to get the actual size
'&sheetnames=false&printtitle=true' + // hide optional headers and footers
'&pagenumbers=true&gridlines=false' + // hide page numbers and gridlines
'&fzr=true' + // do not repeat row headers (frozen rows) on each page
'&attachment=false' +
gid;
// '&size=0&fzr=true&portrait=false&fitw=true&gridlines=false&printtitle=true&sheetnames=false&pagenumbers=true&attachment=false&gid='+gid;
var url = ss.getUrl().replace(/edit$/, '') + 'export?format=pdf' + pdfOpts
var options = {
headers: {
'Authorization': 'Bearer ' +  ScriptApp.getOAuthToken()
}
}
options = {muteHttpExceptions: true};
var blobresponse = UrlFetchApp.fetch(url, options);
var CandidateName = ss.getRangeByName("Nom.Candidat").getValue();
var blob=blobresponse.getBlob().setName(ss.getName() + " - " + CandidateName +".pdf" );
var emailAddress=Session.getActiveUser().getEmail();
var signature = Gmail.Users.Settings.SendAs.get("me", emailAddress).signature; 
var mess = "Voulez-vous envoyer votre rapport  à l'adresse : " + emailAddress;
var ans= Browser.msgBox("Courriel", mess, Browser.Buttons.YES_NO);
if (ans===Browser.Buttons.NO){return;}
var mess="Votre rapport a été envoyé à l'adresse : " + emailAddress;
//var ss=SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Recherche");
var data = ss.getSheetByName("Données");
const corps = data.getRange("A24:E27").getValues();
const htmlTemplate = HtmlService.createTemplateFromFile("HtmlSigTemplate");
htmlTemplate.corps = corps;
var emailSubject = "Vérifications pré-emploi complétées" +" - "+ CandidateName;
const htmlForEmail = htmlTemplate.evaluate().getContent() + "--" + "<br>" + signature;
console.log(htmlForEmail);
//var emailMessage="Bonjour," + "nn" + "J’ai le plaisir de vous informer que les vérifications sont complétées pour le candidat indiqué au tableau de résultats pré-emploi suivant:" + "nn" + "Bonne journée !" + "<br>" + signature;
var shts=ss.getSheets();
GmailApp.sendEmail(
emailAddress, 
emailSubject, 
corps,
{htmlBody: htmlForEmail},
{attachments:[blob]});
Browser.msgBox("Courriel", mess, Browser.Buttons.OK); 
}

试试这个:

GmailApp.sendEmail(emailAddress,emailSubject,corps,{htmlBody:htmlForEmail, attachments:[blob]});

我想你有一个支架}不合适的

最新更新