email file as attachment...

Hello all,

i am on hp-ux 11.23...i am trying to send an email as an attachement but it dose not seem to work...after reading on google i found that we can use uuencode to send file at attachement...here is my file and the syntax

$ cat test.txt

NAME
---------
TEST

$ uuencode test.txt test.txt | mailx -s "TEST VIEW AUTOMATION" email@domain.com
$

but now here is the problem...i do get and email with subject line as "TEST VIEW AUTOMATION"
but do not get a atttachment...get some garbage (lol) in the body as below...

begin 644 test.txt
M"DY!344@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@"BTM+2TM+2TM
M+2`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@("`@"D--1$)44U0@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@
4("`@("`@("`@("`@("`@("`@"@H@
`
end

so what am i doing wrong here ??

You are making the entire body of the email, the attachment. If you edit the received email and input the body to uudecode, you will get your original text.
Search "email attachment" in this forum, there are lots of examples.

Here's an example I did for some folks at work (ksh on Solaris). It sends the same file as 2 attachments just to show how it's done.

Create a text file by doing this:

 
who > example.txt

then run this script called mailtest:

 
#!/bin/ksh
##
##  mailtest - example to show how to do attachments.
##
 
# set the body of the message.
MAILBODY="This is the body of the e-mail"
 
# If an ascii file, convert CR/LF so it will open properly in Outlook.
unix2dos -437 -ascii example.txt attach.out
 
(print $MAILBODY; uuencode attach.out example.txt; uuencode attach.out example1.txt) | \
    mailx -s "mail example 2 attachments" <user>@<domain.com> 
if (( $? != 0 ))
  then print "$0: uuencode or mailx failed"
       exit 3
fi
exit 0
 

You will get an e-mail with the same file attached twice.

Thanks i figured it out...

uuencode test.txt test.txt |mailx -m -r touser@domain -s "attach testing" fromuser@domain

but now it messes up by text.txt file...the output has some squares and stuff like that.... any idea how to get rid of that ??

How about you try the code he posted and see if that works instead?

I tired that but dose not work on HP-UX

In what way does it "dose not work"? :wall:

I guess that you are using a Microsoft mail reader. Need to convert the unix test file to MSDOS format text file.

ux2dos test.txt | uuencode test.txt | mailx -m -r touser@domain -s "attach testing" fromuser@domain

Note that "test.txt" in the "uuencode" command is just the name by which the mail reader will see the file attachment. It needs to be ".txt" if you want to be able to open it automatically with Windows Notepad.

Btw. I think your "fromuser" and "touser" are reversed.