linux - [Solved-5 Solutions] How to send a file as an email attachment using Linux command line - ubuntu - red hat - debian - linux server - linux pc



Linux - Problem :

$ cat mysqldbbackup.sql | mailx [email protected]
click below button to copy the code. By - Linux tutorial - team

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

Linux - Solution 1:

echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- [email protected]
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 2:

gzip -c mysqldbbackup.sql | uuencode mysqldbbackup.sql.gz  | mail -s "MySQL DB" [email protected]
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 3:

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]
click below button to copy the code. By - Linux tutorial - team

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

Linux - Solution 4:

Depending on your version of linux it may be called mail.

mail -s "Backup" -a mysqldbbackup.sql [email protected] < message.txt
click below button to copy the code. By - Linux tutorial - team

or also:

cat message.txt | mail -s "Backup" -a mysqldbbackup.sql [email protected] 
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 5:

mpack -s subject file [email protected]
click below button to copy the code. By - Linux tutorial - team

Unfortunately mpack does not recognize '-' as an alias for stdin. But the following work, and can easily be wrapped in an (shell) alias or a script:

mpack -s subject /dev/stdin [email protected] < file
click below button to copy the code. By - Linux tutorial - team

Related Searches to - linux - linux tutorial - How to send a file as an email attachment using Linux command line