How do I send a file as an email attachment using Linux command line? How do I send a file as an email attachment using Linux command line? linux linux

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


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


Or, failing mutt:

gzip -c mysqldbbackup.sql | uuencode mysqldbbackup.sql.gz  | mail -s "MySQL DB" backup@email.com


Depending on your version of linux it may be called mail. To quote @David above:

mail -s "Backup" -a mysqldbbackup.sql backup@email.com < message.txt

or also:

cat message.txt | mail -s "Backup" -a mysqldbbackup.sql backup@email.com