带有正在编码的附件的发送邮件

lig*_*ght 1 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="-q1w2e3r4t5"'
 echo "this is a test message"
 base64 $ATTACH 
) | sendmail $MAILTO
Run Code Online (Sandbox Code Playgroud)

我的电子邮件消息是这样发送的,没有附件:

this is a test message
dGVzdCBhdHRhY2htZW50
---q1w2e3r4t5--
Run Code Online (Sandbox Code Playgroud)

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

mir*_*los 5

好的,今天心情不错。这是一个有效的(已测试):

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
Run Code Online (Sandbox Code Playgroud)

但请自己一个忙,阅读电子邮件(RFC822 及其替代品)和 MIME(2047 年左右的 RFC)。