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

ID : 10448

viewed : 43

Tags : linuxemailcommand-linelinux

Top 5 Answer for How do I send a file as an email attachment using Linux command line?

vote vote

99

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 
vote vote

82

Or, failing mutt:

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

72

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  
vote vote

63

From looking at man mailx, the mailx program does not have an option for attaching a file. You could use another program such as mutt.

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

Command line options for mutt can be shown with mutt -h.

vote vote

56

I use SendEmail, which was created for this scenario. It's packaged for Ubuntu so I assume it's available

sendemail -f sender@some.where -t receiver@some.place -m "Here are your files!" -a file1.jpg file2.zip

http://caspian.dotconf.net/menu/Software/SendEmail/

Top 3 video Explaining How do I send a file as an email attachment using Linux command line?

Related QUESTION?