Sending Attachments Using Mailx
Sometimes it’s just better to attach a file to your email than to “cat” the contents into the email body. Later versions of mailx support the “-a” option for handling attachments. With the older mailx you will need the “uuencode” utility installed. On CentOS/RHEL you can install it by doing this:
yum install sharutils
To send the actual attachment:
uuencode filename.txt filename.txt | mailx -s "Subject" user@domain.com
Nice and easy.
Another way of sending attachments is to use Mutt (yum -y install mutt):
echo "message body" | mutt -a "/tmp/attachment.txt" -s "subject" -- recipient@domain.com