How to auto-create and auto-apply labels to emails depending on the sender email address?
Example: Once I receive an email from no-reply@amazon.ca, Gmail will automatically create a new label "amazon.ca" and auto-apply "amazon.ca" to this message.
Please don't confuse with manual filters. I am talking about Gmail creating labels for me automatically.
Best Answer
Here is a script that does this. Set a trigger to run it every 5 minutes (the interval can be changed, but then you should change the variable
interval
accordingly).It gets the recent threads in inbox. Only the threads with one message are considered, to avoid labeling based on replies, etc.
Also, if some of your messages skip inbox but you still want to auto-label them, remove
is:inbox
part from the linevar threads = GmailApp.search(...
.