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:
- Use mutt command to send files as mail attachments under Linux / UNIX oses
- Please refer the the "uuencode" man page for more information.
- Email FAQ to a friend
- Printable version
- Rss Feed
- Last Updated: 4-14-08

{ 12 comments… read them below or add one }
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,
Thank-you very much… exactly what I needed !
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
Jakki,
The faq has been updated to include your cat command.
hai,
while using uuencode i get some junk value in mail
Let me know why this is happening….
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,
How to send the mail from AIX server to yahoo / gmail id.
$ (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
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.comEnjoy
How do I put in the reply-to and change the origination email using this mail command. The multiple attachments works great!
Thanks,
Vasanthi
Doesn’t work for me Only one file get attached to email properly and others are displayed with junk char’s
Thanks
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