1834149 Members
2267 Online
110064 Solutions
New Discussion

Attaching file to email

 
John Curtis
Occasional Advisor

Attaching file to email

I'd like to send a file with mail or mailx as an attachment rather than as part of the body of the email. I can't seem to find instructions on how to do this. Can anyone help?

Regards
5 REPLIES 5
Michael Tully
Honored Contributor

Re: Attaching file to email

Craig Rants
Honored Contributor

Re: Attaching file to email

Here is a little script I use. You will probably get a ton of responses on this one, this thread comes through about once a week.

GL,
C

#!/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
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Sridhar Bhaskarla
Honored Contributor

Re: Attaching file to email

Hi,

uuencode with mailx's -m option will do the needful.

uuencode file file |mailx -m -s "subject' mailid

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Dave La Mar
Honored Contributor

Re: Attaching file to email

Here is one I use extensively in variations -
ux2dos /path/to/file_to_send | uuencode newfile.txt | mailx -m -s "Subject" user@xxx.com

The ux2dos insures the file gets the correct ascii character translations.
Best of Luck
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Deshpande Prashant
Honored Contributor

Re: Attaching file to email

Hi
Try this-
#/usr/bin/uuencode attachment attachment |mailx -m -s "Heading for email'

Thanks.
Prashant.
Take it as it comes.