0

I am using Google App Script and I am relatively new to coding. I am trying to send an email with an HTML body, but the entire formatting is dropped in Gmail.

To fix it, I came across the Juice Inliner Tool to add the CSS stylesheet to the HTML source. But I have no clue how to use it in Google App Script. Please help me with some guidance or any reference code on this.

So far I have the code to convert a Google Doc into an HTML Page. Now I want to input the HTML code finalhtml into the Juice Inline tool and return that code instead of finalhtml.

function doc2html(googleDocId){

  const exporturl = 'https://docs.google.com/feeds/download/documents/export/Export?id='+googleDocId+'&exportFormat=html'; //export and hold the document as HTML in the constant exprotUrl
  
  //set the required fetch parameters to run the UrlFetchApp
  const fetchParam = {
    method :"get",
    headers : {
      "Authorization":"Bearer "+ScriptApp.getOAuthToken()
    },
    muteHttpExceptions:true
  };

   var finalhtml = UrlFetchApp.fetch(exporturl,fetchParam).getContentText(); // holds the actual HTML code for the doc in the variable finalhtml.

GmailApp.sendEmail('mailId','Subject', finalhtml,{htmlBody: finalhtml});

}
Tamaal
  • 1
  • 1
  • [This](https://stackoverflow.com/questions/73574929/how-do-i-use-evalurlfetchapp-fetch-to-load-external-javascript-in-my-google?noredirect=1&lq=1) may help you get started – TheMaster Sep 08 '22 at 13:56
  • Please add a [mcve] (include the commands used to send the email as it might be possible that referred tool will not be needed) – Rubén Sep 08 '22 at 15:47
  • I updated the code with the mail sending code. Thank you for the prompt resonse! – Tamaal Sep 13 '22 at 16:34

0 Answers0