小编典典

linux mail <file.log具有Content-Type:application / octet-stream(Gmail中的noname附件)

linux

我一直在用

 mail -s "here is a log file" "person@example.com" < log/logfile.log

过去通常带有标头:

User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

但是现在文件越来越长了,我得到了无名附件,原因是:

User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

因此,如果其他所有方法均失败,请查阅手册man mail

NAME
       mailx - send and receive Internet mail

SYNOPSIS
       mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops]
              [-A account] [-S variable[=value]] to-addr . . .

这些选项似乎都不有用,那么我该如何强制Content-Type: text/plain


阅读 476

收藏
2020-06-07

共1个答案

小编典典

手册页是一个不错的起点!继续阅读,直至进入本MIME TYPES节,并密切注意以下内容:

否则,或者如果文件名没有扩展名,则使用内容类型text / plain或application / octet-
stream,第一个用于文本或国际文本文件,第二个用于包含除换行符和水平字符以外的格式字符的任何文件制表符。

因此,如果您的邮件包含换行符和制表符之外的“格式字符”(通常表示控制字符),则它将自动分类为application/octet- stream。我敢打赌,如果您仔细查看数据,您会发现一些控制字符左右浮动。

您可以通过以下方法解决此问题:

  • 包括日志文件作为附件(使用-a)而不是主要邮件正文,并设置~/.mime.types文件以将*.log文件标识为文本/纯文本。
  • 使用类似的方法过滤掉控制字符tr
  • 使用另一个MUA,例如mutt发送邮件。实际上,您可以自己制作一条消息并将其直接发送给sendmail
    (
    

    echo To: person@example.com
    echo From: you@example.com
    echo Subject: a logfile
    echo
    cat logfile.log
    ) | sendmail -t

2020-06-07