2017-08-29 81 views
1

我嘗試使用下面的代碼在我的郵箱附加一個html文件(谷歌從驅動器):收到與谷歌Apps腳本附件發送郵件拋出異常

function myFunction() { 
    var message = 'Hi'; 
    var fileId ='0B0azXoe_2qFTzNYa1p5eUd0c2s'; // My html document ID 
    var file = DriveApp.getFileById(fileId); 
    var subject = 'Saved Transaction Cleardown logs'; 
    var blob = Utilities.newBlob('mail', 'application/vnd.google-apps.document', 'stc.html'); // I am not sure about the above line, Hope that is where i am wrong 
     MailApp.sendEmail('[email protected]', subject, 
        message, 
        { attachments: [file.getAs(MimeType.HTML), blob], 
         name: 'Automatic Emailer Script' 
        }); 
} 

例外: 我們對不起,發生服務器錯誤。請稍等,然後重試。

+0

您是否嘗試稍後再試一次? –

+0

是的,但仍然得到相同的錯誤:( –

+0

當你正在調試,錯誤發生在同一行代碼或是它的一些隨機行碰撞? –

回答

1

這是一個更合適的方式來實現你的目標:

function myFunction() { 
    var message = 'Hi'; 
    var fileId ='0ByLGhvnaCIQsZXcteeRWd0e344eFE'; // My html document ID 
    var file = DriveApp.getFileById(fileId); 
    var subject = 'Saved Transaction Cleardown logs'; 
     GmailApp.sendEmail('[email protected]', subject, 
        message, 
        { attachments: [ file], 
         name: 'Automatic Emailer Script' 
        }); 
} 

改變HTML文件的ID。 你甚至不需要獲得blob。檢查here

+0

感謝Riyafa !!現在的工作 –

相關問題