1
votes

I'm trying to write a script that uses the gmail API to forward messages from my inbox to new recipients.

This guide recommends sending the base64 encoded string for the e-mail. Presumably, I could get the existing e-mail using the get method with format=raw, edit the base64 encoding to change the recipients, and send the new message along.

The messages I'm sending are quite large (many attachments), so this process (of downloading a massive base64 string, decoding it, doing some regex substituion, re-encoding it, and then re-uploading it) will take a long time. It also seems very cumbersome to use regex to manipulate a MIME email message.

It seems that there should be an easier way...? Perhaps some way to do this directly via the API?

1

1 Answers

0
votes

Try to use the MailApp.sendEmail(). You can use that script to send to multiple receivers so sending messagees to many people wont be that cumbersome.

// 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]
 });

If you want additional samples, try this SO thread.