Operating System - HP-UX
1837932 Members
2764 Online
110124 Solutions
New Discussion

Sending documents as attachments that may be in binary mode with mailx

 
SOLVED
Go to solution
MAD_2
Super Advisor

Sending documents as attachments that may be in binary mode with mailx

I have been reading on some threads that I though could relate to my scenario here but did not find a solution to my problem.

I am trying to figure out a way to send files as attachments by using mailx or sendmail withouth having those embeded in the body of the message. What I want to be able to send are image files, MS Word documents, spreadsheets, etc. from my HP-UX (11.0) to Outlook email accounts or any other email accounts with the original file format and I do not want the file embbeded in the body of the message. I have tried the uuencode and that did not not give me positive results, i.e.:

uuencode file.gif file.gif | mailx -m -s "Test" email@address.com

Thanks,
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
23 REPLIES 23
harry d brown jr
Honored Contributor

Re: Sending documents as attachments that may be in binary mode with mailx


When you say it doesn't give you positive results, what do you mean?

does the, as in your example, gif file become unreadable?

live free or die
harry
Live Free or Die
MAD_2
Super Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

Harry, thanks for your prompt reply! What I get is in the body of the email a bunch of unreadable characters. In other words, I do not get an attachment, I get the document embedded as a message.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
harry d brown jr
Honored Contributor

Re: Sending documents as attachments that may be in binary mode with mailx


Maybe something like metamail:

http://www.shelldorado.com/articles/mailattachments.html#mime

live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: Sending documents as attachments that may be in binary mode with mailx


Also, try dropping the "-m", someone in this thread say's it produces "mime" type :

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x0e6b7e990647d4118fee0090279cd0f9,00.html

live free or die
harry
Live Free or Die
Arockia Jegan
Trusted Contributor

Re: Sending documents as attachments that may be in binary mode with mailx

Adam,

Did u try with some other files? If no, try it out. I'm using the mailx with the syntaxt (Used by you) for last 2 years. I don't have any isues.
MAD_2
Super Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

Harry, thanks for the help.

I also tried without the -m (yes, the -m seems to produce mime) and although I do get a chance to read the text information from my "MS word" document, I still get the document itself embedded in the body of the email. In other words, I am NOT getting an attachment, I am getting the document as body of the email. This is my syntax:

uuencode /tmp/swagent_log.doc /tmp/swagent_log.doc | mailx -s "This is a test" email@address.com

File gets embedded in body of message when received in my outlook email account.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
MAD_2
Super Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

Arockia,

I just tried a "jpg" file with this syntax and all I got was garbage in the body of the message:

uuencode /tmp/friend.jpg /tmp/friend.jpg | mailx -s "This is a test" email@address.com
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
A. Clay Stephenson
Acclaimed Contributor

Re: Sending documents as attachments that may be in binary mode with mailx

My weapon of choice for this is elm. You can use either the interactive version or the command-line version. It's very easy to do multiple attachments as well. NOTE: If you are using the command-line version you must first create a .elm directory in the sender's home direwctory; the interactive version will create one automatically.

Here's a scripting example:


Simply include the following syntax in your mail textfile (e.g) my_message

-----------------
This is some sample text.
[include myfile1 application/octet-stream]

This is some more stuff.

[include myfile2 application/octet-stream]

That's all folks
------------------

Then, elm -s "Sample Subject" daffy@looneytoons.com < my_message

The above will generate 2 separate attachments.

If it ain't broke, I can fix that.
MAD_2
Super Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

A. Clay, you have been great help in the past. I tried your method but got this:

Contents of my text file (elmtst.txt)
[include /tmp/swagent_log.doc application/octet-stream]
[include /tmp/friend.jpg application/octet-stream]

My command line synstax:

elm -s "Test message" email@address.com < /tmp/elmtst.txt

Result, output:

Include file has BINARY data.
Include file has BINARY data.
Include file has BINARY data.
Include file has BINARY data.
Sending mail...
Mail sent!

I got no email. The mailx was sending the files embedded as body of the email.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Ceesjan van Hattum
Esteemed Contributor

Re: Sending documents as attachments that may be in binary mode with mailx

Hi,
My trick is to use a script calling mailx. There are a lot of perl-scripts, containing lines like:

$to="somebody@somewhere.com"
$subject="sometalking"
$cc=""
$bcc=""
$body="..."
but...
$attachements exists as well:
for this you need to have installed the perlmodule MIME:Base64
I used it to sent attachements trough a webinterface:


function mail_attachement_html($to , $sujet , $message , $fichier , $typemime , $nom , $reply , $from){
function mail_attachement_html($to , $sujet , $message , $fichier ,
$typemime , $nom , $reply , $from){
$limite = "_parties_".md5(uniqid (rand()));

$mail_mime = "Date: ".date("l j F Y, G:i")."\n";
$mail_mime .= "MIME-Version: 1.0\n";
$mail_mime .= "Content-Type: multipart/mixed;\n";
$mail_mime .= " boundary=\"----=$limite\"\n\n";

$limite2 = "_parties_".md5 (uniqid (rand()));


//Le message en texte simple pour les navigateurs qui n'acceptent pas le
HTML
$texte_simple .= "This is a multi-part message in MIME format.\n\n";
$texte_simple .= "------=$limite\n";
$texte_simple .= "Content-Type: multipart/alternative;\n";
$texte_simple .= "\tboundary=\"----=$limite2\"\n\n";

$texte_simple .= "------=$limite2\n";
$texte_simple .= "Content-Type: text/plain; \tcharset=\"US-ASCII\"\n";
$texte_simple .= "Content-Transfer-Encoding: quoted-printable\n\n";
$texte_simple .= strip_tags(eregi_replace("
", "\n",
$message));
$texte_simple .= "\n\n";

//le message en html original
$texte_html = "------=$limite2\n";
$texte_html .= "Content-Type: text/html;
charset=\"US-ASCII\"\n";
$texte_html .= "Content-Transfer-Encoding: quoted-printeble\n\n";
$texte_html .= $message;
$texte_html .= "\n\n\n------=$limite2--\n";

//le fichier
$attachement = "------=$limite\n";
$attachement .= "Content-Type: $typemime; name=\"$nom\"\n";
$attachement .= "Content-Transfer-Encoding: base64\n";
$attachement .= "Content-Disposition: attachment;
filename=\"$nom\"\n\n";

$fd = fopen( $fichier, "r" );
$contenu = fread( $fd, filesize( $fichier ) );
fclose( $fd );
$attachement .= chunk_split(base64_encode($contenu));

$attachement .= "\n\n\n------=$limite\n";
return mail($to, $sujet, $texte_simple.$texte_html.$attachement,
"Reply-to:
$reply\nFrom:
$from\n".$mail_mime);

}

So no uuencode but using base64.
Regards,
Ceesjan
MAD_2
Super Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

OK, anyone has more ideas on this issue?
I've been using mailx and sendmail with uuencode and neither one works to send to Outlook email accounts. I am currently going to check on mpack but not sure.

Any other tips?
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Frank Slootweg
Honored Contributor

Re: Sending documents as attachments that may be in binary mode with mailx

The problem is that mailx(1) can not do/handle *real* attachments, i.e. while everything looks OK on the HP-UX/UNIX side, mailers like Outlook get confused because there are no headers like:

Content-Type: application/octet-stream;
name="..."
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="..."

mailx generates *some* MIME headers, like

Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

but that does not signify an *attachment*.

I.e. like other posters have mentioned, you need something like metamail or a new version of elm (that does/handles attachments).

If you do not get a solution here, it is probably best to re-ask the question in the messaging Forum.
Frank Slootweg
Honored Contributor

Re: Sending documents as attachments that may be in binary mode with mailx

Re: Harry's suggestion to leave *off* the "-m" option.

Earlier, I did not check that because that seemed the wrong way to do it, leaving *off* the MIME headers, but I just tried it 'for fun', and for *me* that works, i.e.

uuencode /etc/passwd /etc/passwd | mailx -m -s "Test" my_address@hp.com franks

gives me a correct attachment in Outlook (2000, Corporate or Workgroup version, i.e. *non*-'Internet' version).

The UNIX copy (to franks) has *no* MIME headers. Apparently this is the trigger for Outlook to be 'smart' and do the right thing when seeing

begin 444 /etc/passwd
M....
.....
M....
end

I don't know why it doesn't work for you, but it works for me.
harry d brown jr
Honored Contributor

Re: Sending documents as attachments that may be in binary mode with mailx

Adam,

Sorry I didn't get back to you earlier yesterday. What is the mail program on the receiving end? It has to be able to identify the attachment, otherwise it will just show the uuencode page data.

What I mean is that if you attempt to send a M$ word document, say a Word 2000 document, and the receiver only has M$ 98, when they are going to see just the uuencode data.

I just tested a M$ W2K word document, and a GIF file without any issues using:

uuencode image028.gif image028.gif | mailx -m -s "image stuff" username@place.com

Your Receiver MUST have a VIEWER that can handle the mime type.


live free or die
harry
Live Free or Die
Sanjay_6
Honored Contributor
Solution

Re: Sending documents as attachments that may be in binary mode with mailx

Hi,

Try "mpack". Download it from hp porting site.

http://hpux.cs.utah.edu/hppd/hpux/Users/mpack-1.5/

Hope this helps.

Regds
Frank Slootweg
Honored Contributor

Re: Sending documents as attachments that may be in binary mode with mailx

Sigh!

*Don't* use /etc/passwd as I did in my example. Doing so might trigger a (false) detection of the "Unix Penguin" trojan horse. For details see for example:
http://securityresponse.symantec.com/avcenter/venc/data/unix.penguin.html

In my case, a (MS-) *Windows* copy of my HP-UX .sh_history file was flagged as possibly containing the trojan horse.
MAD_2
Super Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

OK, these are my latest findings (thanks everyone for the help so far, I may have to start a new message because this is becoming quite large):

1. On the receiving end I tested with MS Outlook 98 and 2000 Corporate or Workgroup editions.
2. The solution that A. Clay provided yesterday sort of worked (weird, when I ran the test yesterday, I did not get anything, but got the emails this morning -- Maybe something wrong with the relay server at the time)
3. With A. Clay's suggestion:

=========================================
Contents of my text file (elmtst.txt)
[include /tmp/swagent_log.doc application/octet-stream]
[include /tmp/friend.jpg application/octet-stream]

My command line synstax:

elm -s "Test message" email@address.com < /tmp/elmtst.txt

Result, output:

Include file has BINARY data.
Include file has BINARY data.
Include file has BINARY data.
Include file has BINARY data.
Sending mail...
Mail sent!
=========================================
I got the two attached documents with the example shown above, but the word document was not readable (the document was created in the same system where I tried to open it) and the jpg image was distorted (you could kind of make up what it was but I came up different than the original)

The uuencode is not working, I have not tried mpack yet but just downloaded it from the depot this morning (thanks Sanjay).

Any clues?
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
MAD_2
Super Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

Here is the image received after I sent it as an attachment using A. Clay's example (how it was received, I am attaching separately the original)
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
MAD_2
Super Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

Sorry, my previous message contains the original image, this is how it was received:
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Justo Exposito
Esteemed Contributor

Re: Sending documents as attachments that may be in binary mode with mailx

Hi Adam,

I've got your problem trying in my system, the problem is when you transfer the gif file from windows environment to UNIX environment you transfer the file as an ascii file, then when you send it by mail obtain a corrupted file.

Try to ftp the gif file to the unix box as a binary transfer method and then send it by mail with your original instruction:
uuencode file.gif file.gif | mailx -m -s "Test" email@address.com

This must works perfect, I'd checked.

Regards,

Justo.
Help is a Beatiful word
SAM_24
Frequent Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

Hi,

Try mutt mail client. It is easy.

http://www.mutt.org/download.html

Regards
Raj
Never quit
benoit Bruckert
Honored Contributor

Re: Sending documents as attachments that may be in binary mode with mailx

Hi Adam,
Many tools to solve your pb.
On my side I'm using nail, you can download at the porting center :
http://hpux.cs.utah.edu/hppd/hpux/Networking/Mail/nail-9.30/

This tools is easy to use, And I have no pb, with any kind of attachments.
Check the file mime.type in the etc directory of this produvt after installation.

hth
Benoit
Une application mal pansée aboutit à une usine à gaze (GHG)
MAD_2
Super Advisor

Re: Sending documents as attachments that may be in binary mode with mailx

Thank you all for your replies. I continued the search for an answer in another thread and I got a positive suggestion. I have not tried the other mentioned mail utilities, but will eventually try them. See Rita's response!

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xdf44c4c76f92d611abdb0090277a778c,00.html
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with