Skip to content

Instantly share code, notes, and snippets.

@lewayotte
Last active April 27, 2022 18:18
Embed
What would you like to do?
Automatically delete fake phishing emails from IT
function filter_emails() {
/// 1day is the smallest increment
var threads = GmailApp.search("newer_than:1d");
for (var i = 0; i < threads.length; i++) {
// get all messages in a given thread
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var body = messages[j].getRawContent();
// Possible headers to filter
// X-PHISH: This is a security awareness phishing simulation test from InfoSec Institute that has been authorized by the recipient organization
// X-Report-Abuse-To: abuse-siq@infosecinstitute.com
if (body.indexOf("X-PHISH: This is a security awareness phishing simulation") > -1) {
message[j].markRead();
message[j].moveToTrash();
}
}
}
}
/*
* Go to script.google.com
* Add new project
* Add the above code
* Click save icon
* Go to Triggers
* Add new trigger
* Everything is gravy
* /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment