Linux 邮件命令文件附件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8574529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:44:29  来源:igfitidea点击:

Linux mail command file attachment

linuxfilebashemailattachment

提问by mausmust

Possible Duplicate:
How do I send a file as an email attachment using Linux command line?

可能的重复:
如何使用 Linux 命令行将文件作为电子邮件附件发送?

I want to send a mail with file attachment in linux with mail command. I have tried this:

我想在 linux 中使用 mail 命令发送带有文件附件的邮件。我试过这个:

mail [email protected] < test.txt

but test.txt is send as message, not as a attachment. I don't want to use mutt or other types of mail alternatives. Also i DON'T want to use uuencode. How can i send a file attachment with pure mail command from bash?

但是 test.txt 作为消息发送,而不是作为附件发送。我不想使用 mutt 或其他类型的邮件替代品。我也不想使用 uuencode。如何使用 bash 中的纯邮件命令发送文件附件?

回答by Speckinius Flecksis

Have a look at How do I send a file as an email attachment using Linux command line?. The answers are pretty complete. So better abandon all hope for solving this with bash commands only. It surely is possible, but it's not worth the pain. BTW why should one want it anyway?

查看如何使用 Linux 命令行将文件作为电子邮件附件发送?. 答案很完整。所以最好放弃只用 bash 命令解决这个问题的所有希望。这当然是可能的,但这不值得痛苦。顺便说一句,为什么无论如何要想要它?

回答by mouviciel

If you want to use only mailfor sending files as attachments, you have to write your own bash scripts for formatting the message according to MIMEand its specification for multipart messages.

如果您只想mail将文件作为附件发送,则必须编写自己的 bash 脚本,以便根据MIME及其多部分消息规范来格式化消息

I've done it once but it was not perfect and worth the try only for educational purpose. Moreover, if you plan to attach binary files, you will need some sort of binary to ascii encoder. At that time I found the C source code of a base64 encoder/decoder that I compiled and used in my bash scripts.

我已经做过一次,但它并不完美,仅出于教育目的值得一试。此外,如果您计划附加二进制文件,您将需要某种二进制到 ascii 编码器。那时我找到了我编译并在我的 bash 脚本中使用的 base64 编码器/解码器的 C 源代码。