Skip to content

Instantly share code, notes, and snippets.

@cspenn
Last active May 11, 2017 23:51
Show Gist options
  • Save cspenn/e64aa13707d38320beb7c8f48ffa6f25 to your computer and use it in GitHub Desktop.
Save cspenn/e64aa13707d38320beb7c8f48ffa6f25 to your computer and use it in GitHub Desktop.
Extract bouncing email addresses
#!/bin/bash
## Exports known "bad mailbox" error messages plus the line before (which usually contains the RFC822 email) to a text file for you to keep your email list clean
## Assumes you have bash, a file of all your bounces named bounces.txt
## Copyright © 2017 Christopher S. Penn
## Released under the GPL
TERM1="does not exist"
TERM2="discontinued"
TERM3="doesn't have a"
TERM4="No Such User"
TERM5="wasn't found at"
TERM6="disabled"
TERM7="couldn't be found"
TERM8="Recipient not found"
TERM9="mailbox unavailable"
TERM10="Amazon SES has suppressed"
TERM11="Recipient address rejected"
TERM12="Unknown mail server"
TERM13="5.1.0 Address rejected"
TERM14="550 unrouteable address"
TERM15="550 relaying denied"
TERM16="5.4.4 Invalid domain"
TERM17="550 Mail is rejected by recipients"
TERM18="550 invalid mailbox"
TERM19="because the address couldn't be found"
TERM20="5.1.1 No Valid or Blank Recipient"
TERM21="Requested action not taken"
TERM22="couldn't be delivered"
TERM23="Invalid Recipient"
TERM24="unknown recipient"
TERM25="Not our Customer"
TERM26="User unknown"
grep -B 1 "$TERM1" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM2" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM3" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM4" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM5" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM6" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM7" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM8" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM9" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM10" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM11" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM12" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM13" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM14" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM15" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM16" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM17" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM18" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM19" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM20" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM21" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM22" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM23" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM24" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM25" bounces.txt >> bouncemsgs.txt
grep -B 1 "$TERM26" bounces.txt >> bouncemsgs.txt
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment