Operating System - HP-UX
1748165 Members
4254 Online
108758 Solutions
New Discussion юеВ

Re: mailx and attachments

 
SOLVED
Go to solution
Rob Nowak
Occasional Contributor

mailx and attachments

I'm trying to automate something I do every week. I need to send an email from w/in HP-UX using mailx. This email must include a text file attachment. Is there any way to do this, or can I only send it as the 'body' of the email?

Or can I use some other program I'm not aware of. Thanks in advance.
right
10 REPLIES 10
Steven Sim Kok Leong
Honored Contributor
Solution

Re: mailx and attachments

Hi,

# uuencode file file | mailx -s 'my_subject' receipient@xyz.com

Hope this helps. Regards.

Steven Sim Kok Leong
S.K. Chan
Honored Contributor

Re: mailx and attachments

Try this (it'll send "myfile" as the attachment)

uuencode myfile myfile|mailx -m -s "hello there" skchan@yahoo.com
S.K. Chan
Honored Contributor

Re: mailx and attachments

Forgot one more thing .. if you want to add text to the email body you can do this .. Eg: "content.txt" is a file with the message.

# uuencode myfile myfile > myfile.out
# cat content.txt myfile.out > final
# cat final|mailx -m -s "hello there" skchan@yahoo.com
Paula J Frazer-Campbell
Honored Contributor

Re: mailx and attachments

Hi

Have a look at how this script does it and use its techniques to achieve your aim.


#!/bin/sh
MAILFILE=/tmp/mailtemp
HEADER=/tmp/header

clear
echo "Enter the email address: \c"
read TO
echo "Enter the Cc email address: \c"
read CC
echo "Enter the Bcc email address: \c"
read BCC
echo "Enter the Subject: \c"
read SUBJECT
echo "Enter the Body: \c"
read BODY
echo "Enter the filename of the attachment: \c"
read DATAFILE

echo To: $TO >> $HEADER
echo Cc: $CC >> $HEADER
echo Bcc: $BCC >> $HEADER
echo Subject: $SUBJECT >> $HEADER
echo "" >> $HEADER
echo "" >> $HEADER
echo $BODY >> $HEADER
echo "" >> $HEADER

cat $HEADER > $MAILFILE
uuencode $DATAFILE $DATAFILE.doc >> $MAILFILE
cat $MAILFILE | /usr/lib/sendmail -t
# rm $MAILFILE
# rm $HEADER


HTH

Paula
If you can spell SysAdmin then you is one - anon
Uday_S_Ankolekar
Honored Contributor

Re: mailx and attachments

Hi,

Try uuencode as others said and also you can use within mailx command

mailx user's email < filename to be attached.

-USA..
Good Luck..
Rob Nowak
Occasional Contributor

Re: mailx and attachments

That worked, the only problem is that when I opened the .txt file sent to my email system using notepad.exe....the lines didn't stay the same. Instead, everything is in one big line (instead of thousands) and there is a dark spot that looks like it signifies the beginning of the next line in the file. Any thoughts?
right
S.K. Chan
Honored Contributor

Re: mailx and attachments

Use "ux2dos" command to convert the format of the file before you send 'em out.
Rob Nowak
Occasional Contributor

Re: mailx and attachments

so are you saying to replace uuencode w/ ux2dos in the following command you gave me earlier:

uuencode myfile myfile|mailx -m -s "hello there" skchan@yahoo.com

If I do that, it sends it w/in the body of the email instead of as an attachment.
right
Rita C Workman
Honored Contributor

Re: mailx and attachments

Here's another thread with some suggestions:

http://my1.itrc.hp.com/cm/QuestionAnswer/1,,0x41950559ff7cd4118fef0090279cd0f9!0,00.html

Just so you have options,
Rita