Skip to content

Instantly share code, notes, and snippets.

@anil3a
Created February 6, 2020 02:59
Show Gist options
  • Save anil3a/43710348a0280e4fec88b00e0455e9c5 to your computer and use it in GitHub Desktop.
Save anil3a/43710348a0280e4fec88b00e0455e9c5 to your computer and use it in GitHub Desktop.
Delete email queue from linux mailq - Postfix - ubuntu - Linux
#!/bin/bash
# Usage
# ./delete-mail-containing-email.sh anil@github.com
EMAILADDY=$1
if [ -z "$EMAILADDY" ]
then
echo "Usage: $0 <email adres>"
exit
fi
echo "Delete all emails addressed to $EMAILADDY from our Postfix queue."
mailq | tail -n +2 | grep -v '^ *(' | awk -v "address=$EMAILADDY" 'BEGIN { RS = "" }
{
# example conditions:
# if ( $7 == "MAILER-DAEMON && $8 == address && $9 == "" )
# if ( $7 == "MAILER-DAEMON && $8 == "" && $9 == address )
# if ( $7 == "MAILER-DAEMON && $8 == address || $9 == address )
if ( $7 == address || $8 == address || $9 == address )
print $1
}
' | tr -d '*!' | postsuper -d -
#!/bin/bash
# Usage
# ./delete-mail-containing-mail-daemon.sh anil@github.com
EMAILADDY=$1
if [ -z "$EMAILADDY" ]
then
echo "Usage: $0 <email adres>"
exit
fi
echo "Delete all emails addressed to $EMAILADDY, and sent by MAILER-DAEMON, from our Postfix queue."
mailq | tail -n +2 | grep -v '^ *(' | awk -v "address=$EMAILADDY" 'BEGIN { RS = "" }
{
# example conditions:
# if ( $7 == "MAILER-DAEMON && $8 == address && $9 == "" )
# if ( $7 == "MAILER-DAEMON && $8 == "" && $9 == address )
# if ( $7 == "MAILER-DAEMON && $8 == address || $9 == address )
if ( $7 == "MAILER-DAEMON" && $8 == address )
print $1
}
' | tr -d '*!' | postsuper -d -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment