Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ctbrecmail.sh
- ----------------8<----------------
- #!/bin/bash
- # Uses base64, cat, curl, and mktemp - all standard Linux commands
- # path/to/ctbrecmail.sh <site> <model> <date> <full path to image>
- # eg.
- # ./ctbrecmail.sh ${siteSanitizedName} ${modelSanitizedName} ${localDateTime(yyyyMMdd-HHmmss)} "${absoluteParentPath}/${modelSanitizedName}_${localDateTime(yyyyMMdd-HHmmss)}.jpg"
- site=$1 # site name
- model=$2 # model name
- datetime=$3 # date/time
- #image=`base64 "$4"` # image base64 encoded
- filename=`echo "${4##*/}"` # image name only, no path
- tmp_file=$(mktemp --suffix=.txt) # temp file for email contents
- # compose email contents
- cat >> "$tmp_file" <<EOF
- From: "Joe Bloggs" <joe.bloggs@yourmailserver.com>
- To: "Johnny" <john.q.public@someotherserver.com>
- Subject: $site - $model
- MIME-Version: 1.0
- Content-Type: multipart/mixed; boundary="MULTIPART-MIXED-BOUNDARY"
- --MULTIPART-MIXED-BOUNDARY
- Content-Type: multipart/alternative; boundary="MULTIPART-ALTERNATIVE-BOUNDARY"
- --MULTIPART-ALTERNATIVE-BOUNDARY
- Content-Type: text/plain; charset=utf-8
- Content-Disposition: inline
- $model: $datetime
- --MULTIPART-ALTERNATIVE-BOUNDARY--
- --MULTIPART-MIXED-BOUNDARY
- Content-Type: image/jpeg
- Content-Transfer-Encoding: base64
- Content-Disposition: attachment; filename="$filename"
- $(base64 "$4")
- --MULTIPART-MIXED-BOUNDARY--
- EOF
- # send email with curl using auths from ~/.netrc
- curl --ssl-reqd \
- --url 'smtps://smtp.yourmailserver.com:465' \
- --netrc \
- --mail-from 'joe.bloggs@yourmailserver.com' \
- --mail-rcpt 'john.q.public@someothermailserver.com' \
- --upload-file "$tmp_file"
- ----------------8<----------------
- ~/.netrc (example)
- ----------------8<----------------
- server smtp.yourmailserver.com
- user joe.bloggs
- password unguessablepassword
- ----------------8<----------------
Add Comment
Please, Sign In to add comment