2017-03-09 130 views
0

我正在嘗試編寫一個腳本,該腳本使用gmail API將消息從我的收件箱轉發給新收件人。使用gmail API發送現有消息

This指南建議發送電子郵件的base64編碼字符串。據推測,我可以使用get方法與format=raw獲得現有電子郵件,編輯base64編碼以更改收件人,併發送新消息。我發送的消息非常大(很多附件),所以這個過程(下載一個龐大的base64字符串,解碼它,做一些正則表達式替換,重新編碼它,然後重新上傳)將會需要很長時間。使用正則表達式來操縱MIME電子郵件似乎也很麻煩。

看來應該有一個更簡單的方法...?也許有一些直接通過API做到這一點的方法?

回答

0

嘗試使用MailApp.sendEmail()。您可以使用該腳本發送給多個接收器,因此向許多人發送消息不會太麻煩。

// Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file. 
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); 
var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html'); 
MailApp.sendEmail('[email protected],[email protected],[email protected]', 'Attachment example', 'Two files are attached.', { 
    name: 'Automatic Emailer Script', 
    attachments: [file.getAs(MimeType.PDF), blob] 
}); 

如果您需要更多樣品,請嘗試此SO thread

+0

感謝您的聯繫。這不是我正在尋找的,因爲我需要將已存在的消息(在我的電子郵件收件箱中)發送給新的發件人,所以這仍然需要我將html正文從代表原始消息的base64字符串中取出。這可能是唯一的選擇,但...... – lsankar4033