【问题标题】:sendmail with attachment being encoded带附件的发送邮件被编码
【发布时间】:2015-02-26 18:44:49
【问题描述】:

我正在尝试在 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...

【问题讨论】:

    标签: unix ksh


    【解决方案1】:

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

    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
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-09
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多