Skip to content

Instantly share code, notes, and snippets.

@uriel1998
Created July 17, 2013 18:27
Show Gist options
  • Save uriel1998/6023127 to your computer and use it in GitHub Desktop.
Save uriel1998/6023127 to your computer and use it in GitHub Desktop.
Simple e-mail autoresponder which doesn't send e-mail to an address more than once.
#!/bin/bash
/usr/bin/getmail -r /home/USER/.getmail/getmail.rc
mailpath=/home/USER/mailpath
tmpdir=$(mktemp -d)
echo "########################################################"
for i in $mailpath/new/*; do
if [ -f $i ]; then
echo "Reading Message $i"
echo "########################################################"
while read line; do
#echo $line
case "$line" in
"From: "*)
tmpemail=$(echo "$line" | sed 's/ *(.*)//; s/>.*//; s/.*[:<] *//')
if grep -Fxqi "$tmpemail" /home/USER/.getmail/emailresponder_list.txt
then
echo "$tmpemail exists in database; fail silently. I shan't be a spammer."
else
tmpfile=$(mktemp -p $tmpdir)
echo "Sending email to $tmpemail"
# so we don't send e-mail to them again.
echo "$tmpemail" >> /home/USER/.getmail/emailresponder_list.txt
# Remember to compose your e-mail FIRST, leaving the TO: line blank!
# this is so the multipart headers don't get overwritten by the MTA
/usr/sbin/sendmail -i "$tmpemail" < /home/USER/.getmail/responding_email.txt
fi
;;
esac
done <$i
rm $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment