Skip to content

Instantly share code, notes, and snippets.

@optyler
Created April 26, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save optyler/0186c938efbef98782557226a46c7a01 to your computer and use it in GitHub Desktop.
Save optyler/0186c938efbef98782557226a46c7a01 to your computer and use it in GitHub Desktop.
List and send, one by one, by email pdf and png files matched within directory where the script is located
#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd "${DIR}"
MAILTO="abcd-1234@xyz.go"
find . -type f -depth 1 -iname "*pdf" -o -iname "*png" | while read f
do
ATTACH=$f
BASENAME=$(basename "$ATTACH")
SUBJECT="Send $BASENAME"
BODY="Auto sent message with attachement $BASENAME"
echo "encode $ATTACH to $BASENAME and send to $MAILTO"
(
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
echo
echo '---q1w2e3r4t5'
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
echo $BODY
echo '---q1w2e3r4t5'
echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
uuencode -m "$ATTACH" "$BASENAME"
echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment