Objective: To send mail (using sendmail) with HTML body and binary attachment.
Followed the guidelines specified in the following links
http://www.unix.com/shell-programming-scripting/159522-sendmail-html-body-attachment-2.html
http://www.unix.com/shell-programming-scripting/58448-sendmail-attachment.html
It is working to the extent that, either HTML body or the binary attachment with uuencode, but not both.
Given below is a snippet of the shell script to sendmail. With this, the HTML body is coming fine, but the attachment is getting encoded/decoded wrongly and unable to view the same.
Please advise.
#!/usr/bin/ksh
export MAILFROM="noreply@site.dom"
export MAILTO="somebody@somesite.com"
export SUBJECT="Test PDF for Email"
export BODY="email_body.htm"
export ATTACH="file.pdf"
export MAILPART=`uuidgen` ## Generates Unique ID
(
echo "From: $MAILFROM"
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary="-$MAILPART""
echo "---$MAILPART"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $BODY
echo "---$MAILPART"
echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
uuencode -m $ATTACH $(basename $ATTACH)
echo "---$MAILPART--"
) | /usr/sbin/sendmail $MAILTO
I am using HP-UX ia64.
Have searched through the forum and web and found references mostly to PHP, Python, etc.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…