0

Currently my code sends an html file within the content of the email. I want to continue sending this email as it currently is being sent BUT i want to include an attachment. So in addition to the html content and attachment which is just a flat file containing some records of data. My current code...

(
echo "To: ${AEGIS_REPORT_DIST_LIST}"
echo "Subject: ${EMAIL_SUB}"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo ""
cat "${FINAL_HTML_TABLE}"
) | /usr/sbin/sendmail -t

Figured it out myself. Here's what worked....

(
echo "To: ${AEGIS_REPORT_DIST_LIST}"
echo "Subject: ${EMAIL_SUB}"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary="MAIL_BOUNDARY""
echo "--MAIL_BOUNDARY"
echo "Content-Type: text/html"
echo ""
cat "${FINAL_HTML_TABLE}"
echo "--MAIL_BOUNDARY"
echo "Content-Type: application/octet-stream; name="$(basename "$NINJA_NON_RESPONSE_RECORDS_FILE_PATH")""
echo "Content-Disposition: attachment; filename="$(basename "$NINJA_NON_RESPONSE_RECORDS_FILE_PATH")""
echo ""
cat ${NINJA_NON_RESPONSE_RECORDS_FILE_PATH}
echo "--MAIL_BOUNDARY--"
) | /usr/sbin/sendmail -t
  • See https://serverfault.com/questions/783831/how-do-you-send-an-attachment-with-sendmail. – chepner Jan 29 '20 at 17:12
  • 1
    It's not hard to piece together a simple MIME message but doing it *robustly* for different corner cases (non-ASCII file names, long lines, different character set encodings) is challenging, especially if the script should be portable. My recommendation would be to switch to a proper MUA like `mutt`. – tripleee Jan 29 '20 at 17:14
  • Possible duplicate of https://stackoverflow.com/questions/28168492/need-to-send-html-mail-with-attachment-in-unix – tripleee Jan 29 '20 at 17:16
  • Possible duplicate of https://stackoverflow.com/q/17359/874188 – tripleee Jan 29 '20 at 17:57

0 Answers0