Wednesday, December 7, 2011

How to send mail using MAILX command in UNIX / LINUX

Simple MAILX command

Below is the syntax to send simple mail using mailx command in UNIX / Linux.
You can use it as command line or used it in your shell script.


$ mailx -s "Mail Subject" test@xyz.com
type body of the mail
...
..
EOT (Ctrl+d)
$

Send attachment using MAILX command

In some cases you may have to send attachment in the mail. Lets see the syntax of sending an attachment using mailx command.

Below is the syntax to attach a file while sending a mail using mailx command in LINUX / UNIX


( cat /root/MailBody.txt
uuencode /root/file_name.txt file_name.txt 
) | mailx -s "Mail Subject" test@xyz.com


Here file_name.txt is the attachment to be attached in the mail
AND MailBody.txt is the text body of the mail.