Non-Domain Filter Forwards
GetNonDomainFilterForwards.py
Purpose
Find filters sharing emails outside the Domain
URL
https://github.com/taers232c/GAM-Scripts3/blob/master/GetNonDomainFilterForwards.py
Edit
"""
# Purpose: For Gmail User(s), list/delete all filters that forward email outside of a list of specified domains
# Note: This script can use Basic or Advanced GAM:
# https://github.com/GAM-team/GAM
# https://github.com/taers232c/GAMADV-XTD3
# Customize: Set DOMAIN_LIST.
# Python: Use python or python3 below as appropriate to your system; verify that you have version 3
# $ python -V or python3 -V
# Python 3.x.y
# Usage:
# 1: Get filters, if you don't want all users, replace all users with your user selection in the command below
# $ Example, Basic GAM: gam all users print filters > filters.csv
# $ Example, Advanced GAM: gam config auto_batch_min 1 redirect csv ./filters.csv multiprocess all users print filters
# 2: From that list of filters, output a CSV file that lists the filters that forward email outside of the specified domains.
# $ python3 GetNonDomainFilterForwards.py filters.csv outsidefilters.csv
# 3: Inspect outsidefilters.csv, verify that it makes sense and then proceed
# 4: If desired, delete the filters
# $ gam csv ./outsidefilters.csv gam user "~User" delete filter "~id"
"""
GAMADV-XTD3 Command
gam config auto_batch_min 1 redirect csv ./filters.csv multiprocess all users print filters
The above command will show filters for all users, active and suspended. To search for just active users (non-suspended) use.
gam config auto_batch_min 1 redirect csv ./filters.csv multiprocess all users_ns print filters
Python Command
python3 GetNonDomainFilterForwards.py filters.csv outsidefilters.csv
Inspect
On Linux
nano outsidefilters.csv
Send File
Get a copy of the OutsideFilters.csv file for analysing.
gam sendemail to <User Email Address> subject "Email Filters Sending Messages Outside the Domain" message "Email Filters Sending Messages Outside the Domain" attach outsidefilters.csv
Get a copy of all the filters for analysing.
gam sendemail to <User Email Address> subject "All Email Filter" message "All Email Filter" attach filters.csv