简体   繁体   中英

Sending emails with attachments from a google spreadsheet

I would like to know the possibilities involved in the concept I am trying to do, and if it will be possible.

I will have a google spreadsheet with 3 columns.

NAME | FILENAME | EMAIL

I will place all the Files in the FILENAME column on my drive, so they will be easily accesible.

What I would like to do is when I load the spreadsheet I and run the script, I would like it to:

Use the NAME as the Email Subject + a string of text. By reading the FILENAME Title I would like it to find the file on drive and attach it to the email.

The EMAIL Column will just be the Email I want to send the FILENAME too.

Is this possible using Google app script?

I know how to send emails using google app script and send specific Row data, I am confused about the attachment FILENAME part.

What you want to do should be easy, there is an optional parameter in the sendMail method to add attachments as an array of Blobs and the DriveApp service has a getBlob method to retrieve these data.

So everything looks like an easy game ;-)

But there is one issue you could meet in the development of your script : files in Google Drive can have the same name... (that's why the getFileByName method returns a file iterator instead of a single file object).

What would you do if 2 or more files have the same name in your drive ?

This is often the source of numerous issues (see this thread for example) so you have to be extremely careful about how you name your files or - probably a better solution - preferably store the files IDs rather than their names. The files IDs are by definition unique and more straightforward to get although not so human friendly I admit ;-)

So I'd suggest you store both values in your spreadsheet, it will make your life much easier !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM