Email Multiple File Attachments From Solairs / AIX / HP-UX / UNIX / Linux Command Line

last updated in Categories , , , , , ,

Hey quick question – How do I mail files from IBM AIX / HP-UX Unix as attachments from my shell scripts or command line?

If you have mutt email client installed, try the mutt command as described here. If you don’t have the mutt command installed, use the following command to email files as attachment from UNIX command prompt or shell scripts.


Task: Email reports.tar.gz File

Type the uuencode command as follows:

uuencode reports.tar.gz reports.tar.gz | mailx -s "My Report" 

Please note that the file name “reports.tar.gz” appears twice on the uuencode command line. You must use same name twice.

Task: Email new office photo along with text message read from a file

Type the command as follows;

(cat mymessage.txt; uuencode office.jpeg office.jpeg) | mail -s "Subject"

Task: Send multiple attachments in a single email

Type the command as follows:
$ uuencode r1.tar.gz r1.tar.gz > /tmp/out.mail
$ uuencode r2.tar.gz r3.tar.gz >> /tmp/out.mail
$ uuencode r3.tar.gz r3.tar.gz >> /tmp/out.mail
$ cat email-body.txt >> /tmp/out.mail
$ mail -s "Reports" < /tmp/out.mail

See also:

Page last updated at 12:33 AM, April 18, 2012.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


26 comment

  1. Hi, the information was quite helpful. I was unable to send an attachement along with mail body. The above combination of cat and mail command helped me.


  2. Thank you so much! I’ve been looking for something like this for a long time. I needed to send multiple attachments and was able to make a quick adjustment to do so:

    $ uuencode r1.tar.gz r1.tar.gz > /tmp/out.mail
    $ uuencode r2.tar.gz r3.tar.gz >> /tmp/out.mail
    $ uuencode r3.tar.gz r3.tar.gz >> /tmp/out.mail
    $ cat email.txt >> /tmp/out.mail
    $ mail -s “Reports” < /tmp/out.mail

  3. Hi every one,

    Please, anybory knows how i send a e-mail with a attached file not on the body of e-mail, but like a file.txt.

    uuencode /tmp/test teste.txt | sendmail -v e-mail_adress

    With the above command it worked, but the command elm doesn´t send de attached file.


      1. Hey use below command..

        uuencode /tmp/test teste.txt | sendmail -f mail_address -v -t

        I dont know how my comment hasnt come properly earlier,..

  4. Task: Send multiple attachments in a single email
    Or try this;
    $ (cat email-body.txt; uuencode r1.tar.gz r1.tar.gz && uuencode r2.tar.gz r2.tar.gz && uuencode r3.tar.gz r3.tar.gz) | mail -s "Subject"


  5. How do I put in the reply-to and change the origination email using this mail command. The multiple attachments works great!


  6. Doesn’t work for me Only one file get attached to email properly and others are displayed with junk char’s


  7. If you are getting junk characters in your e-mail rather than an attachment, check to see if the text file you cat has a carriage return/new line at the end. If not uuencode does not seem to handle it properly.

  8. send maill with body multiple attachment and cc list
    cat mail_body.doc > out.mail
    uuencode file1 rename_file1 >> out.mail
    uuencode file2 rename_file2 >> out.mail
    echo ‘~c‘ >> out.mail
    mailx -s “Reports” $TO < out.mail

    it really works ~~

  9. What if I want to send it to a dynamic list of users, instead of always hardcoding the recipient’s email address in there ?

  10. Thank you so much!! I replaced mail with mailx, then it worked in our Solaris box. This is so useful!! Thank you for posting!

  11. I cannot seem to send multiple files using AIX. The body and the first file appear properly, however the subsequent attachments show up as random text. Is it possible that my OS or Lotus notes can’t seem to process multiple requests? I have tried both the && suggestion and the /tmp/out.mail.

    Any thoughts?

  12. $ (cat mymessage.txt; uuencode office.jpeg office.jpeg) | mail -s “Subject”

    Can you please let me know if the file would be attached to the email even if its size is 0, when the above command is used?

  13. I want to know if i send any attached file for more than one E-Mail address whether there will be individual copy will be send to each E-Mail address

  14. My requirement is that there is two log files i want to grep specific contents of both the files and save it in a file and then send a mail with the new file as an attachement.


  15. Is it possible to send multiple files using wildcards. I would like to do this.

    $ uuencode *.tar.gz *.tar.gz > /tmp/out.mail

    Is this possible to use wildcards like ” * ” or ” ? “.


Leave a Comment