Send Emails with email list in excel file and attachments in google drive

Describe the Workflow

I’m trying to send emails with attachments using an Excel file and attachments uploaded into Specific Google-Drive Folder

So, here’s the list of the files&folders on the specific folder named: Conv-Test
image

and here’s the content of the USA folder for example
image



The EmailList.xlsx file content demo as below:
image

This list will be longer, with about 20-30 records, the AttachmentsFolder will be the same as the Folder name in Google drive that have the attachments



The Email Subject and Body will be the same for all emails.



So, what I’m trying to achieve is to Send Emails with this scenario and loop till the end of the email list:

Send an email to [email protected] and put any fixed subject and in the body just: Hello Tommy, Please check the attached file/s,
and regarding the attachment, it will go into USA folder since it’s on the Excel file, and upload all the content (1 PDF or Multiple PDFs) as attachments and send it, Then wait 10 Seconds and go the next email and so on !



SO, i’ve started with listing all googledrive files and folder within the specific folder

and i have no idea how to do this operation



Information on your n8n setup

  • n8n version: 0.197.1 [SelfHosted/Docker]
  • Database you’re using : [default: SQLite]
  • Running n8n with the execution process : [main]
  • Running n8n via: [Docker]

Hey @MotazHakim, this is a tough one and you would need to implement several different concepts to make this work.

My suggestion would be to do something like this:

  1. Read the Excel file, use the Split in batches node to split up the items into batches of 1
  2. Inside the loop for each individual batch: list and download all relevant files from Google Drive
  3. Build and send the email
  4. Close the loop and process the next batch

Especially the “build and send the email” part will be tricky as you have an unknown number of files, all appearing as their own item. You would need to include custom code to make this work (converting multiple items into a single item with multiple binary properties). So, it might be worth considering alternatives instead of making your life hard. Is creating a shareable link for each folder an option, so you can simply include the link to each folder in your emails?

1 Like

Hi @MotazHakim,

You can try an approach to the following workflow, but as @MutedJam rightly points out maybe it is easier to share each folder to its recipient.

Because if there is not the same number of files in each of them, it is difficult to attach all files in the same email (plus you can exceed the maximum sending weight for attachments), so in this approach, the user will receive an email for each file in the corresponding folder.

Also, in order not to exceed the sending limits of the Gmail API, I have placed a one second pause between each loop.

:wink:

2 Likes

Hello @MutedJam
Thanks for your reply.

So regarding your suggestion

  1. valid point
  2. i don’t know how to download all relevant files since there’s sub folders inside the main folder!!
  3. the option to send a sharable link on google drive is not applicable

Hi @martinhache
Many Many thanks for taking the time building this demo specificly for me
let us analyze it

  • The switch node you used as it’s only 3-4 records !!, but in real, it will be 20-30 records, and every record with Unique Email and attach So, i don’t think it will work like that
  • on Route 0 (USA) you List, then Split excel !!!, then Download, then send gmail, for sure since you specific the case for example (USA) we need to manually put the ID of the USA folder to be downloaded, and then you put a split and looped it !!! i think it’s wrong to loop in the excel file, since we are in USA already !!
  • Regarding Email sending limit, we have a Mail server so, no worries

Another easy approche

In Excel file, i’ve added a Folder ID (Will make this folders permanent)

only the Pdfs inside each folder is changable


So, the idea is as this workflow:

Results

image

image


So to explain it

will open the spreadsheat, split it, Google Drive List based on the Folder ID on the split node
download the folder with the folder ID, send email to email in the split node, use the name and country in the subject and body

This workflow is working perfectly and exactly as i want, and i’ve used this function to merge multiple binaries as attachments

Thanks alot for your help

2 Likes