Unix 正在编码附件的sendmail

Unix 正在编码附件的sendmail,unix,ksh,Unix,Ksh,我试图在unix中使用sendmail功能,但似乎无法获得附件…我的代码如下: export MAILTO="me@myco.com" export SUBJECT="test mail" export ATTACH="/home/tstattach" ( echo "To: $MAILTO" echo "Subject: $SUBJECT" echo "MIME-Version: 1.0" echo 'Content-Type: multipart/mixed; boundary="-

我试图在unix中使用sendmail功能,但似乎无法获得附件…我的代码如下:

export MAILTO="me@myco.com"
export SUBJECT="test mail"
export ATTACH="/home/tstattach"
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo "this is a test message"
 base64 $ATTACH 
) | sendmail $MAILTO
我的电子邮件是这样发送的,没有附件:

this is a test message
dGVzdCBhdHRhY2htZW50
---q1w2e3r4t5--

我如何让附件通过?它似乎以一种奇怪的方式对其进行编码…我也尝试了uuencode而不是base64,但后来我收到一个错误,说uuencode未找到…

好的,今天感觉很好。这是一个有效的(经过测试的):

export-MAILTO=”me@myco.com"
导出主题=“测试邮件”
export ATTACH=“/home/tstatach”
(
回显“日期:$(日期-R)”
回显“收件人:$MAILTO”
回显“主题:$Subject”
echo“MIME版本:1.0”
echo'内容类型:多部分/混合;边界=“-q1w2e3r4t5”
回声
回声'-q1w2e3r4t5'
echo“内容类型:文本/普通;字符集=utf-8”
echo“内容传输编码:8比特”
回声
echo“这是一条测试消息”
回声'-q1w2e3r4t5'
echo“内容类型:text/plain;charset=utf-8;name=attach.txt”
echo“内容传输编码:base64”
echo“内容配置:附件;文件名=attach.txt”
回声

base64好的,今天感觉不错。这是一个有效的(测试):

export-MAILTO=”me@myco.com"
导出主题=“测试邮件”
export ATTACH=“/home/tstatach”
(
回显“日期:$(日期-R)”
回显“收件人:$MAILTO”
回显“主题:$Subject”
echo“MIME版本:1.0”
echo'内容类型:多部分/混合;边界=“-q1w2e3r4t5”
回声
回声'-q1w2e3r4t5'
echo“内容类型:文本/普通;字符集=utf-8”
echo“内容传输编码:8比特”
回声
echo“这是一条测试消息”
回声'-q1w2e3r4t5'
echo“内容类型:text/plain;charset=utf-8;name=attach.txt”
echo“内容传输编码:base64”
echo“内容配置:附件;文件名=attach.txt”
回声
base64
export MAILTO="me@myco.com"
export SUBJECT="test mail"
export ATTACH="/home/tstattach"
(
    echo "Date: $(date -R)"
    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/plain; charset=utf-8'
    echo 'Content-Transfer-Encoding: 8bit'
    echo
    echo "this is a test message"
    echo '---q1w2e3r4t5'
    echo 'Content-Type: text/plain; charset=utf-8; name=attach.txt'
    echo 'Content-Transfer-Encoding: base64'
    echo 'Content-Disposition: attachment; filename=attach.txt'
    echo
    base64 <"$ATTACH"
    echo
    echo '---q1w2e3r4t5--'
) | sendmail $MAILTO