I need to send mail in unix with 2 attachments and the subject in html format.
i did the following, it helps in getting the attachment but not the body content in the mail
#!/bin/bash
from="[email protected]"
to="[email protected]"
subject="Status"
boundary="ZZ_/afg6432dfgkl.94531q"
body="mail_body.txt"
attachments=( "FiC.txt" "FiE.txt")
# Build headers
{
printf '%s\n' "From: $from
To: $to
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=\"$boundary\"
--${boundary}
Content-Type: text/plain; charset=\"US-ASCII\"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
cat $body
"
for file in "${attachments[@]}"; do
[ ! -f "$file" ] && echo "Warning: attachment $file not found, skipping" >&2 && continue
#mimetype=$(get_mimetype "$file")
printf '%s\n' "--${boundary}
Content-Type: text/html
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$file\"
"
base64 "$file"
echo
done
printf '%s\n' "--${boundary}--"
} | /usr/sbin/sendmail -t -oi
mail_body.txt's contents:
echo "<html>
<head>
<title> Status</title>
</head>
"
Can help in getting html content printed in body part of mail?
/usr/sbin/sendmail -t -oiwithnland try it yourselfman nland read up on it