我做了一个类似的脚本,它检查“ Received From:”,您可以根据需要在domains
变量中添加任意多个域。
//without http:// etc, just domain-name.com or domainname.com ....
var domains = [
'secureserver.net',
];
//This is not the best solution, a better solution would be to add a filter like this for example => From: #domainname.com
//and then this app would read your GMail filters and test whether it begins with # to apply the next function if so.. but I couldn't find a way to read GMail settings from here
function filterVia() {
// get all threads in inbox
var threads = GmailApp.getInboxThreads();
for (var i = 0; i < threads.length; i++) {
Utilities.sleep(100);
// get all messages in a given thread
var messages = threads[i].getMessages();
// iterate over each message
for (var j = 0; j < messages.length; j++) {
// log message subject
var content = messages[j].getRawContent();
for (var k = 0; k < domains.length; k++) {
//make domain name as regexp
var re = new RegExp('\\.|\\-', 'gi');
var b = domains[k].replace(re, '\\$&');
var regex = new RegExp("Received\: from .*" + b,'gim');
var does_match = regex.test(content);
if(does_match){
//MARK AS READ (maybe spares you an unnecessary notification)
messages[j].markRead();
//DELETE THE MESSAGE
messages[j].moveToTrash();
}
}
}
}
}
Report as Spam
通过单击Gmail按钮会收到的每封邮件吗?这应该适用于其他邮件。顺便说一句,永远不要取消订阅垃圾邮件,它只会确认您的地址是正确的。