How to check an approved email?

I’m currently building a workflow that:

  • get emails from an IMAP account
  • read a .csv file on local host containing approved emails
  • check if the sender is in the list of approved emails
  • will perform other actions after

What are the options for checking if the sender is in the list of approved emails ?

2 Likes

Hey @BMCMLXV,

Welcome to the community,

You should try extracting the CSV to rows then Filter rows with “approvedEmail == senderEmail”.

If you get at least 1 row back, it’s approved; if 0 rows, it’s not.

Let me know if it helped!!

Another workaround is to avoid the Code node and use a Merge node.

I would first normalize the sender email from the IMAP trigger into a field like email, using an Edit Fields node. Then I would also normalize the approved email column from the CSV into the same field name, also called email. After that, you can use a Merge node in a matching mode to compare both branches by the email field. If the sender exists in the CSV list, the Merge node should return a matched item. Then you can continue the workflow only when there is a match.

The important part is that both sides need to have the same comparable value. For example, the IMAP sender should be only user@example.com, not something like John Doe <user@example.com>, and the CSV emails should be trimmed and lowercased if possible.

So the flow would be something like this.

Email Trigger IMAP → Edit Fields → Merge

Read File from Disk → Extract CSV → Edit Fields → Merge

Then after the Merge node, continue only with matched results.

If the approved email list does not change often, another simpler option is to store the approved emails somewhere easier to query, like Google Sheets, Airtable, a database table, or even n8n static data, instead of reading the CSV from disk every time.

Thank you for your help.
I designed the workflow accordingly and her is where i am, with 2 questions

  1. How to make the Read File node execute when Email Trigger is triggered?
    2.The Merge node doesn’t work properly. What do i missed in its setting?

Hi @BMCMLXV

I think the Read File node should be connected to the same trigger as a separate branch. That way it runs in the same execution, and then the Merge node can combine both inputs properly.

1 Like

Thank you @Haian_Abou-Karam
This works well. Here is the corrected version.

2 Likes

@BMCMLXV

I’m happy that the workflow is working at the end.

1 Like