I am trying to send an e-mail
using Unix
that has an HTML
Body and an attachment.
The code works without the attachment part, but when I added the lines for the attachment, the mail I received just displayed everything as plain text.
This code does not seem to work, please help:
MAIL_TO="receiver@mail.com"
MAIL_FROM="sender@mail.com"
MAIL_SUBJECT="MAIL SUBJECT"
ATTACHMENT=sample.txt
HTML_FILE=sample.html
(
echo "From: ${MAIL_FROM}"
echo "To: ${MAIL_TO}"
echo "Subject: ${MAIL_SUBJECT}"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary="MAIL_BOUNDARY";"
echo "Content-Disposition: inline"
echo "--MAIL-BOUNDARY"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat ${HTML_FILE}
echo "--MAIL-BOUNDARY"
echo "Content-Type: text/plain; name="${ATTACHMENT}""
echo "Content-Disposition: attachment; filename="${ATTACHMENT}""
echo "Content-Transfer-Encoding: base64"
base64 ${ATTACHMENT}
echo "--MAIL-BOUNDARY"
) | /usr/sbin/sendmail "${MAIL_TO}"