目的:HTML体和二进制附件发送邮件(使用sendmail)。
遵循以下链接指定的指导方针
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
这是工作的范围内,,或者HTML或身体与UUENCODE二进制附件,但不能同时使用。
下面给出的shell脚本的sendmail的一个片段。 与此相关,HTML身体就要罚款,但附件是越来越编码/解码错误,无法查看相同。
请指教。
#!/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
我使用的HP-UX IA64。 已经通过论坛和网络搜索,发现引用主要是PHP,Python等
从BASE64电子邮件中更改的内容传输编码类型UUENCODE解决了这个问题。 感谢迄今投入。
下面给出的是作品的修改后的脚本。
#!/usr/bin/ksh
export MAILFROM="noreply@domain.com"
export MAILTO="mail.to@gmail.com"
export SUBJECT="Test PDF for Email"
export BODY="email_body.htm"
export ATTACH="file.pdf"
export MAILPART=`uuidgen` ## Generates Unique ID
export MAILPART_BODY=`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 ""
echo "--$MAILPART"
echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""
echo ""
echo "--$MAILPART_BODY"
echo "Content-Type: text/plain; charset=ISO-8859-1"
echo "You need to enable HTML option for email"
echo "--$MAILPART_BODY"
echo "Content-Type: text/html; charset=ISO-8859-1"
echo "Content-Disposition: inline"
cat $BODY
echo "--$MAILPART_BODY--"
echo "--$MAILPART"
echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: uuencode"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
echo ""
#uuencode -m $ATTACH $(basename $ATTACH)
uuencode $ATTACH $(basename $ATTACH)
echo "--$MAILPART--"
) > email_`date '+%Y%m%d_%H%M%S'`.out
| /usr/sbin/sendmail $MAILTO