Created
April 26, 2017 14:43
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | |
cd "${DIR}" | |
MAILTO="[email protected]" | |
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