如何使用mailx发送使用附件和html正文

时间:2014-09-04 12:30:44

标签: html linux shell content-type mailx

我想使用mailx发送一封电子邮件,邮件上有附件和HTML代码。 将Content-type设置为“text / html”邮件在主体上附带文件二进制内容而不是附加。

echo "" >> $MAILFILE
echo "<HTML>" >> $MAILFILE
echo "<HEAD>" >> $MAILFILE
echo "</HEAD>" >> $MAILFILE
echo "<BODY>" >> $MAILFILE
echo "<table border="1">" >>$MAILFILE
echo "<tr bgcolor=#C0C0C0>" >>$MAILFILE
echo "<td><b>OUTAGE</b></td>" >>$MAILFILE
echo "<td>$OUTAGE_COUNT</td>" >>$MAILFILE
echo "</tr> </table><br>" >>$MAILFILE
echo "</table>" >> $MAILFILE
echo "</BODY></HTML>" >> $MAILFILE

(uuencode outage.zip outage.zip;cat $MAILFILE) | mailx -s "Outage Payments Status
Content-type: text/html" $distro -- -f ${EMAIL_FROM}

结果 - Body的电子邮件:

begin 644 outage.zip M4$L#!!0````(`,:$(T5RYN"0#P```.D#```3`!4`;W5T86=E7W!A>6UE;G1S M+F-S=E54"0`#)&X'5"1N!U15>`0`.GX1@5-0@`(3A5$P"D;!,`5<&%Y;65N=',N8W-V550%``,D;@=457@``%!+!08``````0`!`$X```!5 %```````` ` end 

1 个答案:

答案 0 :(得分:0)

Instead use sendmail as follows :

#!/usr/bin/ksh

export MAILTO="spam@ebay.com"
export SUBJECT="Mail Subject"
export BODY="/tmp/email_body.html"
export ATTACH="/tmp/attachment.txt"
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $BODY
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 uuencode -m $ATTACH $(basename $ATTACH)
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO