linux mailx
Plain text file pipelined to Linux mailx turns to “Content-Type: application/octet-stream” which is recognized as an attachment by some email client. The command is like this:
通过管道传输到Linux mailx的纯文本文件将变为“内容类型:应用程序/八位字节流”,某些电子邮件客户端将其识别为附件。 该命令是这样的:
$ cat log.txt | mail -s "Updated log file" -r "from@example.com" "to@example.com"
I expect it to be:
我希望它是:
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
But it turns out to be:
但事实证明是:
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
And from the email client (Gmail, thunderbird, etc), it is recognized as an attachment.
并且从电子邮件客户端(Gmail,雷鸟等)将其识别为附件。
How can I force the content to be inlined in the mail as “Content-Type: text/plain”?
如何强制将内容作为“内容类型:文本/纯文本”内联?
From the “MIME types” of the man page of mailx:
在mailx手册页的“ MIME类型”中:
If there is a match with the extension of the file to attach, the
given type/subtype pair is used. Otherwise, or if the filename has no
extension, the content types text/plain or application/octet-stream
are used, the first for text or international text files, the second
for any file that contains formatting characters other than newlines
and horizontal tabulators.如果与要附加的文件扩展名匹配,则
给定的类型/子类型对。 否则,或者文件名没有
扩展名,内容类型为text / plain或application / octet-stream
用于第一个用于文本或国际文本文件 ,第二个用于
对于任何包含换行符以外的格式字符的文件
和水平制表符。
If the log.txt file contains formatting characters other than newlines and horizontal tabulators, it’s type will be recognized by mailx
as “application/octet-stream”.
如果log.txt文件包含换行符和水平制表符以外的格式字符,则mailx
会将其类型识别为“ application / octet-stream”。
Again, from the man page of cat
:
-v, –show-nonprinting use ^ and M- notation, except for LFD and TAB
-v,–show-nonprinting使用^和M-表示法,LFD和TAB除外
The trick is to add -v
as cat
‘s option to “show” the nonprinting characters as this:
诀窍是添加-v
作为cat
的选项,以“显示”非打印字符,如下所示:
cat -v log.txt | mail -s "Updated log file" -r "from@example.com" "to@example.com"
This works well for my testing.
这对我的测试来说效果很好。
linux mailx