Download specific gmail attachment using IMAP

Hi may I know if someone know how to set specific email attachment to download using IMAP and transfer to FTP server?

I already try to connect IMAP to FTP Server but no filtering on what specific email need to be downloaded, my plan is to set condition like filename or email ID and download the specific email attachment when gmail receive new email may I know if is it possible?

Hey @rodskie123, the IMAP node can be a bit tricky at times but downloading attachments and then processing them in n8n shouldn’t be a problem. Are you struggling with anything in particular?

Hi Jan, currently I already tried to create a test workflow that can download an attachment from gmail to my FTP server folder but no specific email selection, as of now anything email with attachment will be downloaded and process to my test workflow, my plan is to filter out the email and able to assign an specific email using filename or content of the email attachment may I know if is it possible to do that?

Yes, the filename will be available in the binary data portion of your item. So you could use an IF node with an expression of {{$binary.attachment_0.fileName}} in the Value 1 field, you could compare this to your expected filename.

For example here I am checking if my filename ends with unsplash.jpg:

If so, the item would be sent to the True output of the IF node and I could then upload it to an FTP server.

{{$binary.attachment_0.fileName}} , my apology but I’m not so familiar with this may I know where did you get your value 1 on the screenshot?

So what I’ve done here (after running my IMAP node and have it fetch an email with a suitable attachment) is this:

  1. Added a new IF node and connected it to the IMAP node
  2. Added a String condition in the IF node:
  3. In the Value 1 field added a new expression:
  4. In the expression editor clicked my way down from Current Node to the respective attachment’s filename:
  5. After closing the expression editor I have then simply selected Ends With as my Operation and typed in unsplash.jpg in the Value 2 field like so:

Now whenever the workflow runs for a new email it would check if the first attachment has a name that ends with unsplash.jpg (you can, of course, change that to anything else - unsplash is simply where I got my test file from).

In a workflow, this would look like so:

Example Workflow

Hope this helps!

Thank you @MutedJam it works!

1 Like

Sweet, thanks so much for confirming!