mailx commannd - Mail and Attachment in same mail

Hi ,
I am using mailx command for sending the mails. Rightnow I am sending the attachment (by using uuencode $filename) as a seperate mail.I wanna send the attachment also with the same mail.

You have to include the following lines in the header of the email to have the file go as an attachment:

Content-Disposition: attachment; filename="filename.ext"
Mime-Version: 1.0
Content-Type: text/plain
... rest of email ...

And you will probably have to not use mailx and use sendmail with a command like:

/usr/sbin/sendmail -t -iep < emailfilename

But, for that to work, the file, emailfilename has to have a From: line, a Date: line and a Subject: line. There has to be a blank line after these header lines, the ones above, and the start of the data.

Here's a commandline script I wrote for AIX, but which should work just about anywhere you have access to sh (bash, ksh, sh):

#!/usr/bin/ksh

if [ $# -lt 4 ] ; then
 echo "USAGE: send.email UNIXDIR UNIXFILE FROM@atsindustrial.com TO@ADDR.com"
exit 1
fi

UNIXPATH="$1"
UNIXFILE="$2"
FROMADDR="$3"
TOADDR="$4"

if [ -f "$UNIXPATH/$UNIXFILE" ] ; then
 OBJECT="$UNIXPATH/$UNIXFILE"
 cat "$OBJECT" | /usr/sbin/sendmail -oi -t -f $FROMADDR $TOADDR
else
 echo "$UNIXPATH/$UNIXFILE not valid..."
 exit 2
fi

exit 0

HTH

From memory, I recall using a command such as:

uuencode file.att file.att | mailx -s "subject" you@somebody.com

is that what you are trying to do?

Hey,

Thanks man, this is great help !! It solved my purpose too to send a mail with an attachment and text as an option.

If I want to attach more then one file to the same mail then what would be the syntax ???

Thanks.
Varun:b:

echo "Email message" > tempfile
uuencode file1.ext file1.ext >> tempfile
uuencode file2.ext file2.ext >> tempfile
uuencode file3.ext file3.ext >> tempfile
.
.
.
mail -s "Subject" user@domain.com < tempfile

FYI: In case you didn't already know it, the first file named in the uuencode command is the source file. Include the path if necessary. The second file is the name that will be used when the recipient extracts it from their email.

Hey,

Thanks for the reply.
One more question regarding the same topic.

How to send a mail which contains the text as well as the attachment file ?

Note :The text to the mail could be hardcoded or could be taken from a file.

Please suggest !!
Appreciate your help !!
Varun:b:

Hey Guys,

Thanks, I got the answer !!
Thanks for visiting !!
Varun.:b: