gdunc

Email contact sheet (Linux)

Jun 13th, 2021 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. ctbrecmail.sh
  2. ----------------8<----------------
  3. #!/bin/bash
  4.  
  5. # Uses base64, cat, curl, and mktemp - all standard Linux commands
  6.  
  7. # path/to/ctbrecmail.sh <site> <model> <date> <full path to image>
  8.  
  9. # eg.
  10. # ./ctbrecmail.sh ${siteSanitizedName} ${modelSanitizedName} ${localDateTime(yyyyMMdd-HHmmss)} "${absoluteParentPath}/${modelSanitizedName}_${localDateTime(yyyyMMdd-HHmmss)}.jpg"
  11.  
  12. site=$1 # site name
  13. model=$2 # model name
  14. datetime=$3 # date/time
  15. #image=`base64 "$4"` # image base64 encoded
  16. filename=`echo "${4##*/}"` # image name only, no path
  17.  
  18. tmp_file=$(mktemp --suffix=.txt) # temp file for email contents
  19.  
  20. # compose email contents
  21. cat >> "$tmp_file" <<EOF
  22. From: "Joe Bloggs" <joe.bloggs@yourmailserver.com>
  23. To: "Johnny" <john.q.public@someotherserver.com>
  24. Subject: $site - $model
  25. MIME-Version: 1.0
  26. Content-Type: multipart/mixed; boundary="MULTIPART-MIXED-BOUNDARY"
  27.  
  28. --MULTIPART-MIXED-BOUNDARY
  29. Content-Type: multipart/alternative; boundary="MULTIPART-ALTERNATIVE-BOUNDARY"
  30.  
  31. --MULTIPART-ALTERNATIVE-BOUNDARY
  32. Content-Type: text/plain; charset=utf-8
  33. Content-Disposition: inline
  34.  
  35. $model: $datetime
  36. --MULTIPART-ALTERNATIVE-BOUNDARY--
  37. --MULTIPART-MIXED-BOUNDARY
  38. Content-Type: image/jpeg
  39. Content-Transfer-Encoding: base64
  40. Content-Disposition: attachment; filename="$filename"
  41.  
  42. $(base64 "$4")
  43.  
  44. --MULTIPART-MIXED-BOUNDARY--
  45. EOF
  46.  
  47. # send email with curl using auths from ~/.netrc
  48. curl --ssl-reqd \
  49. --url 'smtps://smtp.yourmailserver.com:465' \
  50. --netrc \
  51. --mail-from 'joe.bloggs@yourmailserver.com' \
  52. --mail-rcpt 'john.q.public@someothermailserver.com' \
  53. --upload-file "$tmp_file"
  54. ----------------8<----------------
  55.  
  56.  
  57. ~/.netrc (example)
  58. ----------------8<----------------
  59. server smtp.yourmailserver.com
  60. user joe.bloggs
  61. password unguessablepassword
  62. ----------------8<----------------
  63.  
Add Comment
Please, Sign In to add comment