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

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:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 12 comments… read them below or add one }

1 Syed 09.06.07 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,

2 Steve 03.05.08 at 5:15 pm

Thank-you very much… exactly what I needed !

3 Jakki 04.14.08 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

4 vivek 04.14.08 at 10:27 pm

Jakki,

The faq has been updated to include your cat command.

5 sathish 06.20.08 at 6:02 am

hai,

while using uuencode i get some junk value in mail

Let me know why this is happening….

6 pgiac 10.20.08 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,

7 TKL 11.21.08 at 12:27 pm

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

8 Guy 12.30.08 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

9 Guy 12.30.08 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

10 Vasanthi 02.13.09 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

11 shanti 06.16.09 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

12 Robin 06.30.09 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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

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

Previous post: AIX UNIX Monitor CPU for optimization and to determine CPU bottlenecks

Next post: Howto run a shell script without changing file access permission