linux mailx_通过管道传输到Linux mailx的纯文本文件变为“ Content-Type:应用程序/八位字节流”(附件)...

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:

同样,在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.

这对我的测试来说效果很好。

Answered by Adam.
亚当回答。

翻译自: https://www.systutorials.com/plain-text-file-pipelined-to-linux-mailx-turns-to-content-type-application-octet-stream-an-attachment/

linux mailx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值