Search code examples
google-apps-scriptgmaildrive

is it possible to download GMail attachment to local folder?


i want to download attachment from gmail and save it to local folder using google script. i did some research about this and i could't find any solution.

so far, i managed to save gmail's attachment to google drive only.

var attachmentBlob = attachment[0].copyBlob();
var file = DriveApp.createFile(attachmentBlob);
folder.addFile(file);

or, is it possible to create a google script to auto download file from google drive?

need some advice.


Solution

  • As @Sujay already mentioned you cannot download a file to a local folder using Google AppScript because GAS runs server-side.

    You have already taken a good step with the code to save the attachment as a file to your Google drive.

    To answer your sub-question 'is it possible to create a google script to auto download file from google drive?', you do not need a script to do that, that is what the Google Drive Desktop App (https://www.google.com.ng/drive/download/) does exactly.

    It syncs all the files you add to your drive to your local-pc. You can also edit Google Drive preferences to sync select folders only, in your case that might be the drive folder referenced in your folder variable.