uuencode and cat a file to an email

Posted on 2011-10-31
Last Modified: 2012-05-12
I want to cat a file to the body of an email and attach a uuencoded file but it's not working in Solaris 8.


  uuencode file.xls attachethisfilename.xls > attachethisfilename.xls
  cat /thisfilewithinthemessagebody | mailx -s "subject line" $emailall < attachethisfilename.xls

Any sugestions?
Question by:jjc_mn
    LVL 37

    Accepted Solution

    Hi jjc_mn, how about this:

    ( cat thisfilewithinthemessagebody; uuencode file.xls uuencode file.xls ) | mailx -s "subject line" $emailall
    LVL 82

    Expert Comment

    by:Dave Baldwin
    What does "it's not working" mean?  I think I see the problem.  Emails with attachments need MIME boundaries defined.  Just 'cat'ing it doesn't do that.  Look at the "View Source" in an email with an attachment and you can see what I'm talking about.  Basic info:   More technical details:
    LVL 31

    Expert Comment

    It should work both the ways given by jjc_mn and gerwinjansen
    Take a look

    In my company a lot of scripts were sending email attachments this way.  But when there was an upgrade to the Exchange server, the server admins did not keep any regard for this kind of attachment and just for the common MIME encapsulation, as a result of which the email system broke.  So I had to write a Perl script to make a MIME thing because mutt was not installed or any other such command line clients

    If you have mutt or can get mutt, then the there is no problem

    echo "email " | mail -s "subject" -a attachment email@address
    LVL 82

    Expert Comment

    by:Dave Baldwin
    I ask because the 'attachment' process should uuencode the file and create the MIME boundaries and maybe doing the uuencode first is causing the problem, not solving it.
    LVL 61

    Expert Comment

    by:gheist (the example should be well explaining)

    In 21st century you do not need to uuencode or base64 encode because 99,9% of mail servers were upgraded in last 10 years and are 8-bit clean, and will let your mail pass without any problem. I think sendmail is only dinosaur to do 8-7 bit conversion on the fly. (odds are high it is just lying around idle on your system)
    LVL 82

    Expert Comment

    by:Dave Baldwin
    I suggest that you look at the source of an email with an attached file, especially an image or PDF.  Virtually all mail clients use the MIME format and base64 encoding to include them in an email.  Images embedded in an email are done the same way.  MIME boundaries are also used to separate plain text and HTML parts of a message.
    LVL 61

    Expert Comment

    Base64 is better forgotten. it wastes space in the age of 8BITMIME capable mailers (I think relevant RFC was already there in 1995 when i started in IT)

    Author Closing Comment

    I had to  change it a little but it works great now. Thanks!.

    ( cat thisfilewithinthemessagebody; uuencode file.xls  file2.xls ) | mailx -s "subject line" $emailall

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now