How to attach a file in mail?

Hi,

I want to know how to send a mail in unix using mailx or mail or sendmail to send a mail with a file attached. I have read the answers from the other threads but I still don't understand. I want to do it in the command line as well as in script.

Can anyone help? DO I need to use uuencode? And can I attach a htm or html file with the mail?

Firebird

mail -s "just to say NT carashed again" billgates@microsoft.com < mypicture.jpeg
it is not a relaible way , chances are high that the image will be unusable the time it arrives at the recipient. :slight_smile:

another way:
(cat mailtext; uuencode mypicture.jpeg mypicture.jpeg) |
mail billgates@micro$oft.com

mailtext is provides contents for mail. The file name "mypicture.jpeg" appears twice on the uuencode command line: the first time to specify the input file name, the second time for the remote extraction file name.

but a flexible, relaible & easy way is to use <b>MetaMail</b>Package. This is the original set of MIME tools written by Nathaniel Borenstein. It works as a stand-alone set of tools for sending messages and encoding/decoding of MIME messages parts or can be set up as a plug-in for other tools. check your system before downloading metamail. new Linux distrubutions includes metamail. if you don't have try this link. after you install MetaMail Package you can use mailto or metasend. <b>metasend</b> is suitable for scripting since you could use it non-interactively.

here is an example:
metasend -b -t someone@somewhere.com -s "My webpage!" -m text/html -f mypage.html

-b batch mode (non-interactive)
-t to Recipient's address
-s subject Title (subject) of the mail message
-m MIME-type MIME content type, i.e. "text/plain", "text/html" || "application/postscript" || "image/jpeg" || "image/gif" || "video/mpeg" ....
-f filename Name of file to attach
-n Next file attachment (needed for multiple file attachments).

here is a very simple text (plain or html) attachment with just one file:
echo "From: $You\nTo: $MAILTO\nSubject: $SUBJECT\n\
Mime-Version: 1.0\nContent-Type: text/plain\n" > /tmp/file
cat MailText >> /tmp/file
/usr/lib/sendmail -t -oi < /tmp/file

above all <b>MetaMail</b> is the suitable way. isn't it?