Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.