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

by on April 25, 2007 · 26 comments· LAST UPDATED April 17, 2012

in , ,

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 26 comments… read them below or add one }

1 Syed September 6, 2007 at 1:37 pm

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 at 5:15 pm

Thank-you very much… exactly what I needed !

Reply

3 Jakki April 14, 2008 at 9:39 pm

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 nixCraft April 14, 2008 at 10:27 pm

Jakki,

The faq has been updated to include your cat command.

Reply

5 sathish June 20, 2008 at 6:02 am

hai,

while using uuencode i get some junk value in mail

Let me know why this is happening….

Reply

6 pgiac October 20, 2008 at 6:41 pm

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 at 9:37 am

Hey,

You can use the command

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

Thnx.

Reply

8 Raj Kamal August 26, 2011 at 9:40 am

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 at 12:27 pm

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

Reply

10 Guy December 30, 2008 at 11:24 am

$ (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 at 1:16 pm

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 at 10:18 pm

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 at 7:41 pm

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 at 9:54 am

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 at 1:48 pm

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 at 3:31 am

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 Hale December 2, 2010 at 7:03 pm

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

Reply

18 prajith July 2, 2011 at 11:45 am

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

Reply

19 lyw January 9, 2012 at 9:45 pm

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

20 Acid Plasm January 11, 2012 at 2:23 pm

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

21 bindu February 3, 2012 at 1:36 pm

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

22 Luke September 28, 2012 at 8:30 pm

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

Reply

23 SriRam February 15, 2012 at 4:57 pm

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

Reply

24 Bhupesh Chavan July 18, 2013 at 2:46 am

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

Reply

25 Omar Butt March 6, 2014 at 5:49 pm

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.

Reply

26 Omar Butt March 6, 2014 at 6:06 pm

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

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , ,

Previous Faq:

Next Faq: