簡體   English   中英

通過 Google 腳本使用 HTML 發送 Email

[英]Send Email using HTML via Google Scripts

我創建了一個腳本,該腳本會將來自 Google 表單的信息填充到模板中,並創建 email 生成的 PDF。 我希望能夠自定義它使用 HTML 發送的 email,但由於某種原因,我無法讓它像過去使用類似腳本一樣工作。

代碼如下。 使用此代碼,email 輸出“請找到您的 ML。<_br/>”(但沒有

我希望 output 是“請找到您的 ML。

[越線]”

    function onSubmit(e) {
  const rg = e.range;
  const sh = rg.getSheet();
  
  //Get all the form submitted data
  //Note: This data is dependent on the headers. If headers, are changed update these as well.
  const Email= e.namedValues['Email Address'][0];
  const Team = e.namedValues['Team'][0];
  const Name = e.namedValues['Name'][0];
  const Time1 = e.namedValues['time1'][0];
  const Adjective1 = e.namedValues['adjective1'][0];
  const LengthofTime1 = e.namedValues['lengthoftime1'][0];
  const Adjective2 = e.namedValues['adjective2'][0];
  const Number1 = e.namedValues['number1'][0];
  const Verb1 = e.namedValues['verb1'][0];
  const Verb2 = e.namedValues['verb2'][0];
  const Noun1 = e.namedValues['noun1'][0];
  
  //Build a new invoice from the file
  //Folder and file IDs
  const MLFolderID = '<Folder ID>';
  const MLFolder = DriveApp.getFolderById(MLFolderID);
  
  const TemplateFileID = '<template ID>';
  const newFilename = 'ML -' + TemplateFileID;
  
  //Make a copy of the template file
  const newTemplateFileID = DriveApp.getFileById(TemplateFileID).makeCopy(newFilename, MLFolder).getId();;
  
  //Get the invoice body into a variable
  var document = DocumentApp.openById(newTemplateFileID);
  var body = document.getBody();
  
  //Replace all the {{ }} text in the invoice body
  body.replaceText('{{team}}', Team);
  body.replaceText('{{name}}', Name);
  body.replaceText('{{time1}}', Time1);
  body.replaceText('{{adjective1}}', Adjective1);
  body.replaceText('{{lengthoftime1}}', LengthofTime1);
  body.replaceText('{{adjective2}}', Adjective2);
  body.replaceText('{{number1}}', Number1);
  body.replaceText('{{verb1}}', Verb1);
  body.replaceText('{{verb2}}', Verb2);
  body.replaceText('{{noun1}}', Noun1);
  
  
  document.saveAndClose();

// define email variables
var subject = 'Subject ML';
var msgHtml = 
"Please find your ML enclosed." + "<br/>";
var attachment = DriveApp.getFileById(newTemplateFileID);

//send email with the file
GmailApp.sendEmail(Email, subject, msgHtml, {attachments: [attachment.getAs(MimeType.PDF)],   from:'email@gmail.com'});
  }

代替

GmailApp.sendEmail(Email, subject, msgHtml, {attachments: [attachment.getAs(MimeType.PDF)],   from:'email@gmail.com'});

利用

GmailApp.sendEmail(Email, subject, msgHtml, {htmlBody: msgHtml, attachments: [attachment.getAs(MimeType.PDF)], from:'email@gmail.com'}); } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM