Home > Software design >  Exception: The parameters (String,String,String,(class),(class)) don't match the method signatu
Exception: The parameters (String,String,String,(class),(class)) don't match the method signatu

Time:12-09

I' trying to figure out the way to resolve my bug, as mentionned in the object. Something is going wrong with

GmailApp.sendEmail.

By the way, I'm absolute novice in GAS coding and if you think that the script can be enhanced, feel free.

    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,"   "\n\n"   "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:"   "\n\n"   "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); 
}

CodePudding user response:

Try this:

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

I think you had a bracket } out of place

  • Related