export all Email forwarding using recipient address map

63 views
Skip to first unread message

Motty Bar

unread,
Nov 30, 2022, 4:57:11 AM11/30/22
to GAM for Google Workspace
there is an option to export all the email forwarding address? 
when I try to use the command 

gam all users show forwardingaddress

I don't see it, I see only if someone did it manually from his inbox 


Kim Nilsson

unread,
Dec 18, 2022, 6:32:42 AM12/18/22
to GAM for Google Workspace
I always use the print command when listing many users. Makes it easier to see.

gam all users print forwardingaddress

Works fine for me when I test.

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
#!/usr/bin/env python

"""
# 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
# 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.
#  $ 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', 'domain2.com',]
domainList = ['mydomain.com',]
inputFileName = sys.argv[1]
outputFileName = sys.argv[2]

with open(outputFileName, 'wb') as outputFile:
  with open(inputFileName, 'rb') as inputFile:
    filters = csv.DictReader(inputFile)
    outsidefilters = csv.DictWriter(outputFile, filters.fieldnames)
    outsidefilters.writeheader()
    for row in filters:
      v = row.get('forward', '')
      if v:
        mg = forward_domain.match(v)
        if mg and mg.group(1) not in domainList:
          outsidefilters.writerow(row)
Reply all
Reply to author
Forward
0 new messages