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

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.

ADVERTISEMENTS

Task: Email reports.tar.gz File

Type the uuencode command as follows:

uuencode reports.tar.gz reports.tar.gz | mailx -s "My Report" you@cyberciti.biz 

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" you@cyberciti.biz

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" you@cyberciti.biz < /tmp/out.mail

See also:

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

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
26 comments… add one
  • Syed Sep 6, 2007 @ 13:37

    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.

    Thanks,

  • Steve Mar 5, 2008 @ 17:15

    Thank-you very much… exactly what I needed !

  • Jakki Apr 14, 2008 @ 21:39

    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” user@my.somewhere.com < /tmp/out.mail

  • 🐧 nixCraft Apr 14, 2008 @ 22:27

    Jakki,

    The faq has been updated to include your cat command.

  • sathish Jun 20, 2008 @ 6:02

    hai,

    while using uuencode i get some junk value in mail

    Let me know why this is happening….

  • pgiac Oct 20, 2008 @ 18:41

    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.

    Command:
    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.

    Tks,

    • Raj Kamal Aug 26, 2011 @ 9:37

      Hey,

      You can use the command

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

      Thnx.

      • Raj Kamal Aug 26, 2011 @ 9:40

        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,..

  • TKL Nov 21, 2008 @ 12:27

    How to send the mail from AIX server to yahoo / gmail id.

  • Guy Dec 30, 2008 @ 11:24

    $ (uuencode r1.tar.gz r1.tar.gz && uuencode r2.tar.gz r2.tar.gz && uuencode r3.tar.gz r3.tar.gz) | mail -s “Subject” user@my.somewhere.com

  • Guy Dec 30, 2008 @ 13:16

    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" user@my.somewhere.com

    Enjoy

  • Vasanthi Feb 13, 2009 @ 22:18

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

    Thanks,
    Vasanthi

  • shanti Jun 16, 2009 @ 19:41

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

    Thanks

  • Robin Jun 30, 2009 @ 9:54

    Excelent

    i tried with
    (uuencode r1.tar.gz r1.tar.gz && uuencode r2.tar.gz r2.tar.gz && uuencode r3.tar.gz r3.tar.gz) | mail -s “Subject” user@my.somewhere.com

    It worked

  • Bob Mar 1, 2010 @ 13:48

    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.

  • Minna Nov 23, 2010 @ 3:31

    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 cc@hotmail.com‘ >> out.mail
    mailx -s “Reports” $TO < out.mail

    it really works ~~

  • Hale Dec 2, 2010 @ 19:03

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

  • prajith Jul 2, 2011 @ 11:45

    This above command holds good for tar files and what about if we have to send a csv file

  • lyw Jan 9, 2012 @ 21:45

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

  • Acid Plasm Jan 11, 2012 @ 14:23

    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?

  • bindu Feb 3, 2012 @ 13:36

    $ (cat mymessage.txt; uuencode office.jpeg office.jpeg) | mail -s “Subject” user@my.yahoo.com

    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?

    • Luke Sep 28, 2012 @ 20:30

      file would be attached to the email even if its size is 0,

  • SriRam Feb 15, 2012 @ 16:57

    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

  • Bhupesh Chavan Jul 18, 2013 @ 2:46

    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.

    Regards,
    Bhupesh

  • Omar Butt Mar 6, 2014 @ 17:49

    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 ” ? “.

    Thanks.

  • Omar Butt Mar 6, 2014 @ 18:06

    I seem to be getting the email in the inbox but not the attachment. This is the command that I am using.

    uuencode reports.tar.gz reports.tar.gz | mailx -s “My Report” you@cyberciti.biz

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.