Sending Unix files as attachments in an email

Hi,

I am executing the following command in order to send a file as an attachment:
mailx -s "Subject" emailID@xyz.com < Testfile.txt

Instead of attaching the file Testfile.txt, it is writing the contents of the file in the email message body. Please advise on how I can send the file as an attachment.

Thanks!!!

the "<" tells the command to take input from whatever is on the other side of it.

Thanks. But if I remove "<" , then where can I mention the attachment file name?
I tried "cat Testfile.txt | mailx -s "Subject" emailID@xyz.com" as well as "uuencode Testfile.txt | mailx -s "Subject" emailID@xyz.com".
Both of them gave me the same result...Contents of Testfile.txt in the email body..The file did not come as an attachment. Please advise.

cat file|uuencode file|mailx -s "subject" address

is that command you are running?

you may try parenthesizing the command for attaching the file:

(cat file|uuencode file)|mailx -s "subject" address
   cat Testfile.txt | ux2dos | mailx -s    " blah blah subject"   Emailaddress, emailaddress

Thanks for your suggestions...But none of these worked..In all these cases, the file content is coming as the message body...may be soem version difference...Anyways, I have to go ahead with it...So, implementing with the file as message body :frowning:

try the following:

uuencode zz.sh zz.sh > mail.txt; cat mail.txt | mailx -s "subject" email_address

The only way I know is to write a script and use sendmail -t option...

---------- Post updated at 19:58 ---------- Previous update was at 19:46 ----------

By my friend Paula (when we were both on HP/ITRC...):
## How to send a doc attachment in unix?
# Look at the following script! (Paula FC, 2003)

#!/bin/sh 
MAILFILE=/tmp/mailtemp 
HEADER=/tmp/header 

clear 
echo "Enter the email address: \c" 
read TO 
echo "Enter the Cc email address: \c" 
read CC 
echo "Enter the Bcc email address: \c" 
read BCC 
echo "Enter the Subject: \c" 
read SUBJECT 
echo "Enter the Body: \c" 
read BODY 
echo "Enter the filename of the attachment: \c" 
read DATAFILE 

echo To: $TO >> $HEADER 
echo Cc: $CC >> $HEADER 
echo Bcc: $BCC >> $HEADER 
echo Subject: $SUBJECT >> $HEADER 
echo "" >> $HEADER 
echo "" >> $HEADER 
echo $BODY >> $HEADER 
echo "" >> $HEADER 

cat $HEADER > $MAILFILE 
uuencode $DATAFILE $DATAFILE.doc >> $MAILFILE 
cat $MAILFILE | /usr/lib/sendmail -t 
# rm $MAILFILE 
# rm $HEADER