Sometimes I have the need to send an email with an attachment directly from the console, to do this I use a small email client called “mutt” it can be installed in Centos using;
yum install mutt
In the home dir of the user thats sending the email, create the following file .muttrc that contains;
set realname=”name of sender”
set from=”emailaddressofsender”
Substitue the name of sender with the name of your choice and the emailaddressofsender needs to be changed to the sending email address.
Then using the following you can send an email with an attachemnt from the command line.
mutt -s “Subject of email” -a /home/user/filetoattach.ext recipient@address.com < /home/user/bodytext.txt
In the above change “Subject of email” to the subject of your choice, the -a option tells mutt to attacth a file, then we specify the path of the file. recipient@address.com needs to be changed to the email address you are sending the email to. The last part of the code reads in the body text of the email from a file.