Sent an email attachment, but the attachment is empty

I'm trying to send a .zip file from my unix box to my work email (email client outlook)

The file name that I'm trying to sent is sites.zip and this is how I do it:

uuencode sites.zip | mailx -s "testing" myname@mydomain.com

When I open the .zip, the zip is empty. Looking around the we, I see that the reason is that I need to convert from unix format to dos format and I can do that by using unix2dos. But when I try I get an error:

unix2dos sites.zip | mailx -s   myname@mydomain.com
could not open /dev/kbd to get keyboard type US keyboard assumed
could not get keyboard type US keyboard assumed

Thanks in advance

You cannot use unix2dos on binary files, it will render the zip unreadable for the unzip. Instead, you will have to uuencode, mail, and then run uudecode on the DOS side to reverse the changes made by uuencode. Then you should be able to unzip the file.

Is there any other way to do it that I don't have to do anything on the other end? because I'm doing an script and I don't want the user do anything on their end. Thanks for your fast reply

What you were doing never made sense in the first place. Any other way to do what?

If you want the contents of the zip to be converted, convert the files before you zip them...

As Corona668 said, convert should be the first thing you do, IF those are text files, which you did not mention. In case they are:
unix2dos files; zip files; uuencode .zip; mail .zip; uudecode .zip; unzip files --> there you are, you have your unzipped, converted files on your DOS side.

No guarantees (you'll need to dry run this) but I find that some Windows compression utilities (eg. WinRAR) can unpack native unix tar files.

I've used such functionalities in production environments quite successfully.

I just did a test, The file that I want to send as an attachment is named text_file.txt

unix2dos text_file.txt

Then I sent it as an attachment likr this

uuencode text_file.txt  | mailx -s "test" myname@domain.com

But when I received the file, the file was empty.

Mail clients are bad at handling uuencoded attachments these days. Some don't understand them at all, some mangle them. Best to use base64 attachments if you can, but I don't know of any way that was as straightforward as uuencode was.

mail is a bit picky about char sets and what it considers binary data. Pls post text_file.txt and the result of both unix2dos and uuencode. For a pure text file, you usually don't need uuencode. Btw, the file is not an attachment but will be the mail text itself.
You can also try to display the source code of the message (<ctrl> u in thunderbird) to help debug the problem.

I sftp to the unix box and I got the text and zip files and I'm able to see them both on my PC. Why I can't see it when I email it. BTW I'm not an expert in unix.

Probably because something's wrong with the email one way or another.

Have you tried viewing the source of the email as suggested? We can't really see your computers from here.

This is the source code:

Received: from FLDP1LUMXC7HB02.domain.com (168.68.75.85) by
MXC7HB05.domain.com (168.68.59.192) with Microsoft SMTP Server
 (TLS) id 8.3.264.0; Wed, 15 Aug 2012 13:31:38 -0400
Content-Type: multipart/mixed;
 boundary="_8ba3ac-2ef3-4d69-84eb-0f92a29d51a5_"
Received: from omzsmtpi03.domain.com (165.122.46.173) by
 MXC7HB02.domain.com (168.68.75.85) with Microsoft SMTP Server
 id 8.3.264.0; Wed, 15 Aug 2012 13:31:36 -0400
To: name@domain.com
X-VzAPP: 1
X-IronPort-AV: E=Sophos;i="4.77,774,1336348800"; 
   d="scan'208";a="85187077"
X-Local: true
Received: from ndcc01-smtp1.domain.com ([148.170.124.35])  by
 omzsmtpi03.domain.com with ESMTP; 15 Aug 2012 17:31:35 +0000
Received: from pdcd35-snmcpe1.ip.mic.com (pdcd35-snmcpe1.ip.mic.com
 [208.112.196.84]) by ndcc01-smtp1.domain.com
 (8.13.8+Sun/8.13.8/vz-mnso-$Revision: 1.5 $) with ESMTP id q7HVZh0010433 for
 <name@one.domain.com>; Wed, 15 Aug 2012 17:31:35 GMT
Received: from pdcd35-snmcpe1.ip.mic.com (localhost [127.0.0.1]) by
 pdcd35-snmcpe1.ip.mic.com (8.13.8+Sun/8.14.2) with ESMTP id q7HVJtD024085
 for <name@one.domain.com>; Wed, 15 Aug 2012 17:31:19 GMT
Received: (from myname@localhost) by pdcd35-snmcpe1.ip.mic.com
 (8.13.8+Sun/8.14.2/Submit) id q7FHVJbp024084 for
 name@one.domain.com; Wed, 15 Aug 2012 17:31:19 GMT
Date: Wed, 15 Aug 2012 17:31:19 +0000
From: david.foo <myname@pdcd35-snmcpe1.ip.mic.com>
Message-ID: <201208151731.q7FHVJbp024084@pdcd35-snmcpe1.ip.mic.com>
Subject: Hi
MIME-Version: 1.0
Return-Path: myname@pdcd35-snmcpe1.ip.mic.com
X-ConvertedToMime: 1

Strange. Please
a) send an e-mail interactively
b) send a simple output like ls|mail ...
c) post your text_file.txt

Ok, here is my resolution;
this is the way I was doing it at first:

 
uuencode file_name.zip | mailx -s "test" my_name@domain.com
 

This is the right way:

 
uuencode file_name.zip fila_name.zip | mailx -s "test" my_name@domain.com
 

The first file_name.zip is naming the file the second file_name.zip is the actual file that you are attaching.

1 Like

Hi,

The same problem i am facing.
I am sending file with csv extension.
However, I am receiving mail with empty file.
Before sending file was containing data.
Any suggestions please...
Thanks.

try:

uuencode file.txt file.txt;mail -s "subject" email@host.com

I will try that one too...
However, I am getting the problem with below command...

echo "Pls. find attached the report." ;
uuencode file.csv file.csv |
mailx -m -s "A report of the changes" email.addr

May I know what is problem with this?
Is "mail" command full proof?

| vs ; gets me everytime... sorry for the confusion.