如何使用 Linux 命令行将文件作为电子邮件附件发送? [英] How do I send a file as an email attachment using Linux command line?

查看:35
本文介绍了如何使用 Linux 命令行将文件作为电子邮件附件发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个脚本,该脚本每晚都在我的 Linux 服务器上运行,该脚本使用 mysqldump 将我的每个 MySQL 数据库备份到 .sql 文件并将它们打包为一个压缩的 .tar 文件.我要完成的下一步是通过电子邮件将该 tar 文件发送到远程电子邮件服务器以进行妥善保管.我已经能够通过将备份文本文件通过管道发送到 mailx 像这样将正文中的原始脚本发送一封电子邮件:

I've created a script that runs every night on my Linux server that uses mysqldump to back up each of my MySQL databases to .sql files and packages them together as a compressed .tar file. The next step I want to accomplish is to send that tar file through email to a remote email server for safekeeping. I've been able to send the raw script in the body an email by piping the backup text file to mailx like so:

$ cat mysqldbbackup.sql | mailx backup@email.com

cat 回显备份文件的文本,该文本通过管道传输到 mailx 程序中,并将收件人的电子邮件地址作为参数传递.

cat echoes the backup file's text which is piped into the mailx program with the recipient's email address passed as an argument.

虽然这完成了我的需要,但我认为这可能会更好,有什么方法可以使用 shell 脚本或其他方式将压缩的 .tar 文件作为 发送到外发电子邮件附件?这将胜过必须处理包含标题数据并且经常有自动换行问题等的非常长的电子邮件.

While this accomplishes what I need, I think it could be one step better, Is there any way, using shell scripts or otherwise, to send the compressed .tar file to an outgoing email message as an attachment? This would beat having to deal with very long email messages which contain header data and often have word-wrapping issues etc.

推荐答案

没有一个笨蛋适合我.它认为电子邮件地址是附件的一部分.不得不做:

None of the mutt ones worked for me. It was thinking the email address was part of the attachemnt. Had to do:

echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.com

这篇关于如何使用 Linux 命令行将文件作为电子邮件附件发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆