I want to send a HTML file as message body and want to attach multiple text files to this email message.
Since html file needs to be sent, sendmail has to be used ( I could not do it using mailx ).
How do you send HTML body email and multiple text attachments using sendmail?
We can include multiple attachments by separating them using a semicolon.
Assuming you have uunecode available in your system you can send email with multiple attachments like this:
#!/bin/bash
...
...
...
BOUNDARY="=== This is the boundary between parts of the message. ==="
{
echo "From: $MAILFROM"
echo "To: $MAILTO"
echo "Subject:" $SUBJECT
echo "MIME-Version: 1.0"
echo "Content-Type: MULTIPART/MIXED; "
echo " BOUNDARY="\"$BOUNDARY\"
echo
echo " This message is in MIME format. But if you can see this,"
echo " you aren't using a MIME aware mail program. You shouldn't "
echo " have too many problems because this message is entirely in"
echo " ASCII and is designed to be somewhat readable with old "
echo " mail software."
echo
echo "--${BOUNDARY}"
echo "Content-Type: TEXT/PLAIN; charset=US-ASCII"
echo
echo "This email comes with multiple attachments."
echo
echo
echo "--${BOUNDARY}"
echo "Content-Type: application/zip; charset=US-ASCII; name="${ZIPFILE}
echo "Content-Disposition: attachment; filename="`basename ${ZIPFILE}`
echo
uuencode $ZIPFILE $ZIPFILE
echo
echo "--${BOUNDARY}--"
echo "Content-Type: application/pdf; charset=US-ASCII; name="${PDFFILE}
echo "Content-Disposition: attachment; filename="`basename ${PDFFILE}`
echo
uuencode $PDFFILE $PDFFILE
echo
echo "--${BOUNDARY}--"
} | /usr/lib/sendmail -t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With