Email multiple file attachment from Solairs / AIX / HP-UX UNIX/ Linux command line

by Vivek Gite on April 25, 2007 · 20 comments

Q. Hey quick question - How do I mail files from AIX / HP-UX UNIX as attachments from my shell scripts or command line?

A. If you have mutt mail client installed, use the mutt as described here.

If you don’t have mutt installed use the following command to email files as attachment from UNIX command / shell prompt / shell scripts.

Task: Email reports.tar.gz

Type uuencode command as follows:
$ uuencode reports.tar.gz reports.tar.gz | mailx -s "My Report" user@yourcorp.com

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

Type the command as follows;
$ (cat mymessage.txt; uuencode office.jpeg office.jpeg) | mail -s "Subject" user@my.yahoo.com

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

Further readings:

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 20 comments… read them below or add one }

1 Syed September 6, 2007

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,

Reply

2 Steve March 5, 2008

Thank-you very much… exactly what I needed !

Reply

3 Jakki April 14, 2008

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

Reply

4 vivek April 14, 2008

Jakki,

The faq has been updated to include your cat command.

Reply

5 sathish June 20, 2008

hai,

while using uuencode i get some junk value in mail

Let me know why this is happening….

Reply

6 pgiac October 20, 2008

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,

Reply

7 Raj Kamal August 26, 2011

Hey,

You can use the command

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

Thnx.

Reply

8 Raj Kamal August 26, 2011

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

Reply

9 TKL November 21, 2008

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

Reply

10 Guy December 30, 2008

$ (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

Reply

11 Guy December 30, 2008

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

Reply

12 Vasanthi February 13, 2009

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

Thanks,
Vasanthi

Reply

13 shanti June 16, 2009

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

Thanks

Reply

14 Robin June 30, 2009

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

Reply

15 Bob March 1, 2010

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.

Reply

16 Minna November 23, 2010

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 ~~

Reply

17 prajith July 2, 2011

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

Reply

18 lyw January 9, 2012

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

Reply

19 Acid Plasm January 11, 2012

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?

Reply

20 bindu February 3, 2012

$ (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?

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 8 + 6 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the simple math so we know that you are a human and not a script.




Previous post:

Next post: