How do I send a file as an email attachment using Linux command line?,
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 firstname.lastname@example.org
cat echoes the backup file’s text which is piped into the
mailx program with the recipient’s email address passed as an argument.
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" -- email@example.com
That’s the answer How do I send a file as an email attachment using Linux command line?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.
The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you