KCD*_*KCD 14 linux email mailx
我一直在用
 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?
lar*_*sks 11
手册页是一个很好的起点!继续阅读,直到你到达该MIME TYPES部分,并密切关注以下内容:
否则,或者如果文件名没有扩展名,则使用text/plain或application/octet-stream的内容类型,第一个用于文本或国际文本文件,第二个用于包含除换行符和水平之外的格式字符的任何文件制表符.
因此,如果您的邮件包含除了换行符和制表符以外的"格式化字符"(通常表示控制字符),它将自动归类为application/octet-stream.我敢打赌,如果仔细观察数据,你会发现一些控制字符浮动.
你可以解决这个问题......
-a)而不是主消息正文,并设置您的~/.mime.types文件以将*.log文件标识为text/plain.tr.使用另一个MUA,例如mutt发送邮件.事实上,您可以自己制作一条消息并将其直接发送至sendmail:
(
  echo To: person@example.com
  echo From: you@example.com
  echo Subject: a logfile
  echo
  cat logfile.log
) | sendmail -t
我最近遇到了类似的问题,最终得到了一个更短的解决方案:
cat -v log/logfile.log | mail -s "here is a log file" "person@example.com"