Tuesday, January 7, 2014

Unix - How to send a mail with subject, attachment and mail body.

Here is the command to send a mail with Subject, Body along with Attachment from Unix.
 
----(echo #BODY uuencode #ATTACHMENT_FILE  ‘#ATTACHMENT_FILE_NAME’ ) | mail –s #SUBJECT #MAIL_RECEICER  
 
For example-(echo $1 uuencode $2 'Purchase Order.pdf') | mail -s $3 $4
Here
·         $1 is the parameter which contain Body part.
·         $2 is the parameter which says about the Location of file to be mailed.
·         $3 is the parameter which says about Subject
·         $4 is the mail recipient. 


OR
-----

You can can use below command from Unix prompt to send a mail with attachment o471883593.out as Required pdf and a mail will be sent to kalpana.deka@something .com

--uuencode o471883593.out Required.pdf | mail kalpana.deka@something .com