I want to send a simple text file as an attachment in an email. When the email is delivered, the attachment is missing, instead, the contents of the attachments are displayed in the email body. Need suggestions to fix it please.

Here is my input:

bash-4.1$ cat test.txt  
HelloWorld !  

bash-4.1$ uuencode test.txt test_attachment.txt|mailx -s 'testing' mail@mail.com  

Here is the output on the email:

begin 664 test_attachment.txt

You may have some incorrect expectation of what the uuendcode ... | mailx ... command is supposed to do.

In the world that uuencode was designed to operate in, there is no such thing as an attachment, because MIME doesn't exist yet. A person who receives a message with uuencoded stuff in it is supposed to see it like this:

From: Alice <alice@example.edu>
To: Bob <bob@example.com>
Subject: Those files you requested

Here you go:

begin 644 something.tar.Z


The recipient is supposed to recognize that the lines from begin to end are a uuencoded file, and pipe those lines (or maybe the whole message) to uudecode, then look for the output file in the current directory.

It's a lot like decoding MIME attachments, but a bigger chunk of it takes place in the brains of the users.

Some modern mailreaders might automatically recognize uuencoded contents, and use a single user interface to present both uuencoded and MIME-attached files. I wouldn't expect any classic unix mailreaders to do that, because it misrepresents what was actually sent, which is a plain text (non-MIME) message.


Some implementations of mailx utility are not able to send attachments. Others (on Linux for example) has a -A flag that takes a filename as its value.

Therefore, if you're on Linux, you will need to write the uuencoded data to a file before using mailx:

$ uuencode test.txt test_attachment.txt >file.uue
$ mailx -A file.uue -s "testing" someone@example.com </dev/null

This sends an email to someone@example.com with an empty body and the attachment from file.uue.

  • Thanks for your response! I tried the below: bash-4.1$ uuencode vin.dat vin_attchment.dat > vfile.dat bash-4.1$ mailx -a vfile.dat -s "testing2" someone@somewhere.com </dev/null The result was that- (i) the attachment has a file and its contents are encoded :( (ii) the body is empty - which is fine I suspect the issue is with the uudecode utility. Do you know any known issues with this pkg please ?
    – Vineet
    Jun 19 '16 at 12:37
  • 1
    If you are using the -A parameter then you don't need to uuencode; mailx will MIME encode and convert things as necessary Jun 19 '16 at 16:28

Almost 2 years later, but... it seems like uuencode or mail is broken on Linux. Or maybe it's working correctly but Outlook is broken. Who knows?

uuencode a.gz a.gz | mail -s "testing uuencode from linux" me@domain.com

uuencode a.gz a.gz | mail -s "testing uuencode from aix" me@domain.com

Sending from Linux, Outlook shows inline uuencode code. Sending from AIX, Outlook shows it as an attachment. Same command, same mail relay, different OS, different results. Oh, maybe it's sendmail(aix) vs postfix(linux)? Anyway, draw your own conclusions about the location of breakage.

Oh, to give a real answer... mailx -a a.gz -s "subject" me@domain.com

uuencode test.txt test_attachment.txt | mailx **-m** -s 'testing' mail@mail.com
  • 4
    This may be correct, but it would be nice to have a slightly more fleshed-out answer.
    – Kusalananda
    Jan 14 '17 at 11:10
echo "\
Subject: My Email Subject at `date \"+%m/%d/%Y %r UTC\"`
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="^A^A^A^A^A"
Content-Transfer-Encoding: 7bit

Content-Type: text/plain; charset=US-ASCII; name="BDY.TXT"
Content-Disposition: inline; filename="BDY.TXT"
Content-Transfer-Encoding: 7bit

My Email Subject at `date \"+%m/%d/%Y %r UTC\"`

Content-Type: text/plain; charset=US-ASCII; name="ZIP_FILE"
Content-Disposition: attachment; filename="ZIP_FILE"
Content-Transfer-Encoding: 7bit

" > /tmp/ZIP_FILE

cat /tmp/MySourceZipFile >> /tmp/ZIP_FILE
echo "
--^A^A^A^A^A--" >> /tmp/ZIP_FILE

/usr/sbin/sendmail "GodSend@Heaven.godcom" < /tmp/ZIP_FILE
  • 4
    Hello Chezhi. This looks like it might be a good start, but code without explanation is not at all helpful. Please add some text to explain what is going on and how it's an answer to the question. Right now it's likely to get deleted.
    – roaima
    Mar 29 '17 at 1:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.