SHARE
Facebook X Pinterest WhatsApp

Email PDFs From the Command Line With Open Source Software uuencode

Written By
thumbnail Juliet Kemp
Juliet Kemp
May 17, 2010
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



I often find myself wanting to email someone an attachment of some sort – PDF, doc, jpg, or whatever. As a rule I’ll do this by scping it to the machine I use for mail (or uploading to gmail), but I’d far rather save time with a command-line oneliner.

Tip of the Trade: Uuencode is a command-line oneliner that saves you time by piping attachments directly into the mail command.

Enter uuencode, which allows you to pipe attachments directly into the mail command. Here’s a basic example:

uuencode article.pdf article.pdf | mail -s 
"Here's that article" juliet@earth.li

The -s option to mail sets the subject line.

Note that you must give the filename twice. If you give it only once, the image will not actually be sent, and mail will wait until you hit Ctrl-D to return to the command line. It will then send the rest of the email, but without the attachment. This is because the first filename is read as the label for the attachment (i.e., it assumes -o), and the default is for uuencode to read from stdin. Without a second filename, it will try to send, as an attachment, whatever you type before you hit Ctrl-D. This means you could do this:

uuencode text.txt | mail -s "Testing text" juliet@earth.li

Then, type a bunch of text in before hitting Ctrl-D, and it would be sent as a text file.

However, a better way to do this is to save your text file, then use:

uuencode text.txt 
If you want a (short) message body as well, try:

(echo 'Hope you find it interesting -- Juliet'; uuencode article.pdf 
article.pdf) | mail -s "Here's that article" juliet@earth.li

Finally, bear in mind that if the machine you're sending from isn't set up with proper reverse DNS, some mail servers will reject the incoming mail. If it's not working, this might be why.

Juliet Kemp has been messing around with Linux systems, for financial reward and otherwise, for about a decade. She is also the author of "Linux System Administration Recipes: A Problem-Solution Approach" (Apress, 2009).

Follow ServerWatch on Twitter

thumbnail Juliet Kemp

Juliet Kemp is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.