Sending email with message body and attachment

Hello experts!!

I am trying to send an email with message body and attachment.but i am getting any one like message body or attachment.

I tried below command:

(echo "subject:test";echo "MIME-Version: 1.0";echo "content-transfer-encoding:base 64";echo "content-type:txt;name=test.txt";cat /path/test.txt) | \
/usr/lib/sendmail -r someone@ex.com -t someone@ex.com

when I tried this, I am getting attachment.

so for message body i tried the below command,

(echo "subject:test";echo "MIME-Version: 1.0";echo "content-transfer-encoding:base 64";echo "content-type:txt;name=test.txt";cat /path/test.txt;\
echo "'cat /path/test.txt'") | /usr/lib/sendmail -r someone@ex.com -t someone@ex.com

I got in attachment "cat /path/test.txt" this line. I read all unix forums and tried commands but didn't work.

please suggest me I want to send message body along with attachment using sendmail command.

mailx is less complicated - the body1 variable is a dummy == empty
exp_file is the attachment

(printf "%s\n%s\n" "$body" "$body1"; uuencode $exp_file $exp_file) |mailx -s "$email_subject" me@mycompany.com

mailx is a simplified frontend for sendmail and talks to it directly after translating your command into sendmail-ese.

yes, I tried the command with sendmail. but in attchment i am getting printf statement. but not message body. please suggest