command when listing many users. Makes it easier to see.
Here's a little python script to find users forwarding outside your list of domains, using filters.
$ cat bin/find_accounts_forwarding_outside_our_domain
# 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 GAM: https://github.com/jay0lee/GAM
or advanced GAM: https://github.com/taers232c/GAMADV-X
# 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.
# $ python GetNonDomainFilterForwards.py filters.csv outsidefilters.csv
# 3: Inspect outsidefilters.csv, verify that it makes sense and then proceed
# 4: Delete the filters
# $ gam csv outsidefilters.csv gam user "~User" delete filter "~id"
import csv, re, sys
forward_domain = re.compile(r"^forward .*@(.*)$")
# Substitute your domain(s) in the list below, e.g., domainList = ['domain.com
',] domainList = ['domain1.com
domainList = ['mydomain.com
inputFileName = sys.argv
outputFileName = sys.argv
with open(outputFileName, 'wb') as outputFile:
with open(inputFileName, 'rb') as inputFile:
filters = csv.DictReader(inputFile)
outsidefilters = csv.DictWriter(outputFile, filters.fieldnames)
for row in filters:
v = row.get('forward', '')
mg = forward_domain.match(v)
if mg and mg.group(1) not in domainList: