Gmail help with make query


I have own mail on own server and sometimes if you send me mail it went to spam. I make filter to Gmail not move to spam any mail sent to this specific address (but then mails from blocked addresses also won’t go to spam).
Likewise, I was thinking about to move via n8n all mails sent to this specific address and at the same time not sent FROM blocked address, I pretty often block mails (mostly some newsletters what remove subscription is not “friendly”/easy). Just, I am not sure how to make this query.

About blocking

If I get annoying mail what I want to block, I do this:
And later I see this:

And also mail address is on blocking list in settings:

Is someone familiar with advanced Gmail searching and could help, or maybe know how else way to do what I need?

Thanks Simon

1 Like

Hi @Shirobachi, from the sounds of it I think you could let Gmail mark the messages as spam (to have your blocking work as expected).

You could then in n8n fetch all messages to your specific address including those marked as spam using a query like to:[email protected]:

In your workflow you can then check in the IF node whether your message is from a blocked sender (or not), e.g. using a boolean condition and an expression like {{['[email protected]', '[email protected]'].includes($json["from"]["value"][0]["address"])}}. This would return true if the from address is either [email protected] or [email protected]. You can of course add as many emails to the array as needed.

If it’s from a good sender, simply remove the Spam label:

There might be ways to achieve this directly in Gmail, but I am not super familiar with their queries and filtering so can only suggest my view on possible n8n approaches here :wink:

Right, I’ll do it that way, thanks!