Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

Can I send email from Linux command line?

sendmail Command Sendmail is one of the most popular SMTP servers in Linux. You can easily send emails directly from the command line using the sendmail command. To route the information, the sendmail command makes use of the network configured on your system.


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 protected]

Or, failing mutt:

gzip -c mysqldbbackup.sql | uuencode mysqldbbackup.sql.gz  | mail -s "MySQL DB" [email protected]

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

mail -s "Backup" -a mysqldbbackup.sql [email protected] < message.txt

or also:

cat message.txt | mail -s "Backup" -a mysqldbbackup.sql [email protected] 

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" [email protected]

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