bash 如何将文件从 Linux 发送到电子邮件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/985846/
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
How can I send a file from Linux to email?
提问by Paul Bullough
How can I send a zip file (~600MB) to an email account? What is the command line should be used in bash?
如何将 zip 文件 (~600MB) 发送到电子邮件帐户?在bash中应该使用什么命令行?
What if I want to FTP the files to a server automatically?
如果我想自动将文件通过 FTP 传输到服务器怎么办?
回答by Alex Brown
Well, in my opinion 600Mb is too large for e-mail, since some clients and servers will choke on that size. But that's your choice, and if you own the webserver then obviously you can do what you like.
嗯,在我看来,600Mb 对于电子邮件来说太大了,因为一些客户端和服务器会因为这个大小而窒息。但这是您的选择,如果您拥有网络服务器,那么显然您可以随心所欲。
The unix command mail can be used (when configured) to send emails.
unix 命令 mail 可用于(配置后)发送电子邮件。
You might also want to look at perl's Net::SMTP module, which is for this sort of thing.
您可能还想查看 perl 的 Net::SMTP 模块,它用于此类事情。
回答by Adam Batkin
Most linux distributions contain a mail
command (from the mailx package). You can attach a file from the command line using the -a
option:
大多数 linux 发行版都包含一个mail
命令(来自 mailx 包)。您可以使用以下-a
选项从命令行附加文件:
mail -s 'file attached' -a /path/to/file [email protected]
That said, most mail systems won't be happy with 600MB attachments.
也就是说,大多数邮件系统不会对 600MB 的附件感到满意。
The ncftppackage has a number of commands that may be useful for automated transferring of files over FTP, in particular the ncftpput
command (see the manpages for more information).
所述的ncftp封装具有数量的命令,其可以是用于文件传输的自动通过FTP是有用的,特别是ncftpput
命令(更多信息参见联机帮助页)。
Depending on where you are sending the file, if the other end supports ssh, it might be better to use tools like scp or ssh and rsync. With public key authentication, you don't even have to worry about embedding a password anywhere.
根据您发送文件的位置,如果另一端支持 ssh,最好使用 scp 或 ssh 和 rsync 等工具。使用公钥身份验证,您甚至不必担心在任何地方嵌入密码。
If you are doing backups, consider a tool like Duplicity(but not for a full zip file as it loses most of its advantages) as it supports a number of protocols, performs compression on-the-fly and can perform incremental backups. Oh, and the backups are encrypted and digitally signed to ensure their integrity.
如果您正在进行备份,请考虑使用Duplicity 之类的工具(但不适用于完整的 zip 文件,因为它失去了大部分优势),因为它支持多种协议,即时执行压缩并可以执行增量备份。哦,备份经过加密和数字签名以确保其完整性。
回答by Paul Bullough
You can split it up with "split" first, send it with "mail" then concatenate it at the other end with "cat".
你可以先用“split”把它分开,用“mail”发送,然后在另一端用“cat”连接它。