How to attach a file & send mail thru script

In shell script how can I attach a file and send a mail.

suppose if I written like the following way

usr/bin/mail 'subject" "mail_id" < file.

a mail goes to the mail-id with the content of file.But I want the file to be atttached to the mail.How can I get it.is there any way for this.

Thanks
Kanth

i think this will work.

usr/bin/ file1.txt | mailx "subject" "mail_id"

Regards,
Swapneel

Read the FAQ

it is not working.I am using sun solaris.

it does not work, so give the error messages you encountered.
Also, did you even try to see what usr/bin/ is on the shell command line??
the actual command might be
/usr/bin/cat file.txt | mailx .........or something similar..

When I use the following command at command prompt it is working.

uuencode filename filename | mail "mail_id".

but when I use in the script it is not working and giving the error

SP2-0734: unknown command beginning "/usr/bin/u..." - rest of line ignored.

before this i open sql connection.I have to close this conncetion before using this command.i will check it.

again problem.
when i use
uuencode "filename" | mailx -s "subject" "mail_id".
it is showing subject but it is not attaching the file to the mail

when i use
uuencode "filename" | mail -s "subject" "mail_id".
it is attaching file but subject is not showing in mail.b'se sun solaris 5.9 does not allow mail command to show subject.

how to do it.

This topic has been discussed many times, a quick search through this forum can help you

Hi,
I want to send html file as attachment using mailx command on linux machine.
Has anybody done this before ?
Appreciate your help !

Regards,
Dnyanesh

what happens when you do this in the script?

uuencode filename filename | mailx -s "subject" user@somewhere.com

ghostdog74 has indicated the correct option, on Solaris the mailx command rather then mail should be used to do this.