Unix/Linux Go Back    

UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

How to attach a file in mail?

UNIX for Dummies Questions & Answers

Thread Tools Search this Thread Display Modes
Old Unix and Linux 03-29-2001
firebirdonfire firebirdonfire is offline
Registered User
Join Date: Mar 2001
Last Activity: 26 April 2001, 11:16 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

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?

Sponsored Links
Old Unix and Linux 03-29-2001
mib mib is offline
Registered User
Join Date: Jan 2001
Last Activity: 8 July 2003, 3:54 AM EDT
Location: Calicut
Posts: 228
Thanks: 0
Thanked 7 Times in 4 Posts
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. Linux

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?

Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to attach multiple file to send mail command AhmedLakadkutta Shell Programming and Scripting 1 09-22-2011 05:30 PM
Script to attach file to mail sfetea Shell Programming and Scripting 4 11-26-2010 07:39 AM
How to attach a file in Linux mail command rohit22hamirpur Shell Programming and Scripting 1 12-05-2008 12:58 AM
How to attach a file & send mail thru script Mar1006 Shell Programming and Scripting 9 10-12-2006 08:54 AM
Need to attach a txt file while sending mail charan81 Shell Programming and Scripting 9 01-12-2006 12:44 AM

All times are GMT -4. The time now is 01:34 AM.