本帖最後由 javacomhk 於 2022-4-29 03:52 編輯
例如個 google doc 係咁
個 function 可以咁寫去測試 sendmail。- function sendEmailfromdoc(){
- // fill in google doc ID
- var id = 'AABBCCDDEEffgghhiijjkkllmmnn' ;
- 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();
- // testing first email send out with replaced fields
- var htmlout1 = html.replace("{{title_1}}","This is My Title for testing one");
- htmlout1 = htmlout1.replace("{{heading_1}}","This is heading One");
- htmlout1 = htmlout1.replace("{{heading_2}}","This is heading Two");
- // Logger.log(htmlout1);
- MailApp.sendEmail({
- to: "myrecipient@gmail.com",
- subject: "Testing EMail from Doc",
- htmlBody: htmlout1
- });
- console.log('email sent !!')
- }
複製代碼 測試 email 結果:
|