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

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

问题描述

我已经创建了运行使用我的Linux服务器 mysqldump的来备份每个我的MySQL数据库.sql文件在每天晚上一起打包它们作为一个脚本一个COM pressed .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

呼应这与作为传递的收件人的电子邮件地址管道输送到的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脚本或其他方式,发送COM pressed .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.

推荐答案

Mutt的那些没有为我工作。它在想的电子邮件地址是attachemnt的一部分。需要做的:

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天全站免登陆