How to send rich text emails with GmailApp?

前端 未结 1 973
[愿得一人]
[愿得一人] 2021-01-27 19:10

I’m trying to send a Google Doc, with all of its formatting, in an email.

function sendGoogleDocInEmail() {

  var doc = DocumentApp.openById(\"example_Id\");
           


        
相关标签:
1条回答
  • 2021-01-27 19:49

    Trying using a combination of this script: https://stackoverflow.com/a/28503601/3520117

    And then using the htmlBody parameter of the MailApp.sendEmail method.

    Untested, but should work:

    function emailGoogleDoc(){
      var id = DocumentApp.getActiveDocument().getId() ;
      var forDriveScope = DriveApp.getStorageUsed(); //needed to get Drive Scope requested
      var url = "https://docs.google.com/feeds/download/documents/export/Export?id="+id+"&exportFormat=html";
      var param = {
        method      : "get",
        headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
        muteHttpExceptions:true,
      };
      var html = UrlFetchApp.fetch(url,param).getContentText();
      Logger.log(html);
    
      var email = person@domain.tld;  
      var subject = 'Subject line';
      var body = "To view this email, please enable html in your email client.";
    
      MailApp.sendEmail(
        email,           // recipient
        subject,         // subject 
        body, {          // body
          htmlBody: html // advanced options
        }
      );
    }
    
    0 讨论(0)
提交回复
热议问题