sending files as attachments

How do I send a file as an attachment on a Unix system

<P>Sending and attaching files on UNIX-like system can be done in a myriad of ways. It really depends on the mail client you are using and how you are using it.
<P>
In web-based clients like Netscape browsers, you simple click and add the attachment from the browser GUI.
<P>
The same is true for almost all GUI-based email clients.
<P>
From the command line, elm(), sendmail() and a host of others allow you to easily send files from the command line.
<P>
Most editors, vi(), et. al. allow you to read in the file, but you might want to convert to an ASCII friendly format first. There are many tools to do this. The old ones had names like uuencode() and uudecode(). Now, there are so many it is hard to keep track of them and there are used in all types of MIME setups.
<P>
To answer your question specifically, you need to specify the exact email client you are using. WWW-based email clients are popular these days, of course; but for auto-generated mail responders, etc. a command line tool is best.

uuencode [file] | mail xxx@xxx.com

this is what I've attempted. I somewhat works.

If I run this from the command line, I only get a portion of the file. I ultimately need to set this up through a crontab, So I am testing it from the command line. When I receive the message, It arrives as an attachment, but the file is corrupted.. I believe it's because of the way I am exiting the mail program. CTRL-D.

The file that ultimately needs to be sent is approximately 12 MB. I figure this would take a while. This is where I decided to try it with a much smaller file (1KB). But it still seems that the mail prog will not close out on it's own.

Let me know what you think or if you need more details.

You need to look for a tool called 'mimencode'. This will do what you want. The documentation details how to process files from the command line.

Have you looked for the tool called 'mimencode' as I mentioned above? The documentation that comes with that tool explains how to use it to attach arbitrary files to an email message.

mimencode (also known as mmencode) is part of the metamail package. You can get a solaris version here: http://www.ibiblio.org/pub/packages/solaris/sparc/
Download to /tmp and "gunzip" it. Then do a "pkgadd -d /tmp"

You should now have mimencode installed in /usr/local/bin

Then you can run something similar to the following script (pipe it to mailx)

<code>#!/bin/bash
#
# Script: sendfile
#
# Purpose: Send the specified file via email as a MIME
# attachment to the specified address.
#
# Author: Anthony E. Greene <agreene@pobox.com>
#
# License: GPL <http://www.gnu.org/>
#
# Note: This script does not include any error checking, so
# it should only be called from within other scripts.
# The correct syntax for using this script is:
#
# sendfile filename user@domain | /path/to/sendmail -t
#

# First we set up some global variables.
# Some code should be added to verify the commandline arguments.
sender=you@yourdomain.com
filename=$1
basefile=`/bin/basename $filename`
recipient=$2

echo From: $sender
echo To: $recipient
echo Subject: File $basefile
echo MIME-Version: 1.0
echo "Content-Type: multipart/mixed; Boundary=\"sendfile-attachment-boundary\""
echo
echo --sendfile-attachment-boundary
echo 'Content-Type: text/plain; charset=us-ascii'
echo
echo This is a MIME encoded message. If your mail software
echo cannot properly handle the attached file, you may need
echo to get a MIME-aware mailer.
echo
echo --sendfile-attachment-boundary
echo "Content-Type: application/octet-stream; name=\"$basefile\""
echo Content-Transfer-Encoding: base64
echo "Content-Disposition: attachment; filename=\"$basefile\""
echo
/usr/bin/mimencode $filename
echo --sendfile-attachment-boundary--</code>

also see this thread: http://forums.unix.com/showthread.php?threadid=568

I have to translate a microfocus COBOL--generated ascii report file into pdf and attach it in an e-mail kicked off from within the following cgi script:
if [ "$EMAIL" = "Y" ]; then
sed -e '/^H_/s///g' <$REPFILE >$REPFILE2

  print "&lt;center&gt;&lt;h3&gt;&lt;br&gt;Emailing to $EMAILID&lt;/h3&gt;&lt;/center&gt;"                  
  \(                                                                           
      echo "To: $EMAILID"                                                     
      echo "Subject: OK - Drawing $DRWID Issue $DRWISS Certified White Report 

Content-Type: multipart/mixed;
boundary=\"------------F31625F689894DCE7A7A828F\"

This is a multi-part message in MIME format.
--------------F31625F689894DCE7A7A828F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit"

      echo "                                                                  

White Report from Certified Data included within:
Drawing ID = $DRWID
Issue = $DRWISS
ChgAnal = $CHG"
if [ "$CHG" = "Y" ]; then
echo "ChgAnalIss = $CHGISS"
fi
echo "Manuf Doc = $MFG"
echo "--------------F31625F689894DCE7A7A828F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
"
cat $REPFILE2
echo "--------------F31625F689894DCE7A7A828F--"
) | mailx -t
------------------------------------------------------------
I can use postprint to go from ascii--->ps, and then I can use Acrobat's distill to convert the ps--->pdf, but how do I then attach the resulting pdf in an e-mail?
I've read all the threads here and I don't see an answer.
Please help. What am I missing? There is no option to mailx to attach, and the RFC822 was no help. We have to use mailx.
Thank you.

Caveat: this is the "dummy" forum, right?
That's where I belong. How do I find mimencode? I did a 'which mimencode' from the command line, and I can't find it. I'm running on a solaris 2.6. Thanks

Thanks! I'll give it a try, but I'm not an SA, and in the past they haven't given me root access to install packages.
I'll see what I can do. The responses have been very helpful. Thanks again