Operating System - HP-UX
1823143 Members
3632 Online
109647 Solutions
New Discussion юеВ

send text file as an attachment

 
SOLVED
Go to solution
Anand_30
Regular Advisor

send text file as an attachment

Hi,

I am writing one script which generates a text file as an output. I need to send this output file as an attachment to the concerned people.
I tried using elm but I am not able to send the file as an attachment.

Can anyone please help me in this problem.

Thanks,
Anand.

7 REPLIES 7
Geoff Wild
Honored Contributor

Re: send text file as an attachment

Best thing to use - mpack:

http://hpux.ee.ualberta.ca/hppd/hpux/Users/mpack-1.5/

Mpack and munpack are utilities for encoding and decoding
(respectively) binary files in MIME (Multipurpose Internet Mail
Extensions) format mail messages.

Works great with text files...



Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Mel Burslan
Honored Contributor

Re: send text file as an attachment

uuencode filename filename | mailx -s "Subject of your mail" user_name@domain.com

this works for me...

HTH
________________________________
UNIX because I majored in cryptology...
James A. Donovan
Honored Contributor

Re: send text file as an attachment

To send multiple attachments, create a file with the following contents:

Subject: ADD SUBJECT HERE
MIME-Version: 1.0
Content-type: multipart/mixed;boundary="zzzz"
Content-Transfer-Encoding: 7bit

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

ADD BODY TEXT HERE

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

ADD ASCII TEXT FOR FIRST ATTACHMENT HERE

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

ADD ASCII TEXT OF SECOND ATTACHMENT HERE

--zzzz--

#############################################

An example of the above method put to use (this is part of a larger shell script where the variables are defined):

## Send out e-mail notifications ##

echo "To: ${MAILTO}" >>/tmp/mymailfile.$$
echo "Subject: ${SUBJ}" >>/tmp/mymailfile.$$
echo "MIME-Version: 1.0" >>/tmp/mymailfile.$$
echo "Content-type: multipart/mixed;boundary=\"zzzz\"" >>/tmp/mymailfile.$$
echo "Content-Transfer-Encoding: 7bit" >>/tmp/mymailfile.$$
echo "" >>/tmp/mymailfile.$$
echo "--zzzz" >>/tmp/mymailfile.$$
echo "Content-Type: text/plain; charset=US-ASCII; name=\"${LOGFILE}\"" >>/tmp/mymailfile.$$
echo "Content-Disposition: attachment; filename=\"$(basename ${LOGFILE})\"" >>/tmp/mymailfile.$$
echo "Content-Transfer-Encoding: 7bit" >>/tmp/mymailfile.$$
echo "" >>/tmp/mymailfile.$$
cat ${LOGFILE} >>/tmp/mymailfile.$$
echo "" >>/tmp/mymailfile.$$
echo "--zzzz" >>/tmp/mymailfile.$$
if [ ${CNT} -eq 1 ]; then
echo "Content-Type: text/plain; charset=US-ASCII; name=\"${ARCHFILE}\"" >>/tmp/mymailfile.$$
echo "Content-Disposition: attachment; filename=\"$(basename ${ARCHFILE})\"" >>/tmp/mymailfile.$$
echo "Content-Transfer-Encoding: 7bit" >>/tmp/mymailfile.$$
echo "" >>/tmp/mymailfile.$$
cat ${ARCHFILE} >>/tmp/mymailfile.$$
echo "" >>/tmp/mymailfile.$$
echo "--zzzz" >>/tmp/mymailfile.$$
fi

cat /tmp/mymailfile.$$ | /usr/sbin/sendmail -t ${MAILTO}
rm /tmp/mymailfile.$$
Remember, wherever you go, there you are...
Patrick Wallek
Honored Contributor

Re: send text file as an attachment

I use this script:

SYSTEM=$(uname -n)

(echo "Subject: ${SYSTEM} filename" ; uuencode filename.txt filename.txt) | /usr/sbin/sendmail user@somewhere.com,user1@somewhere.com
A. Clay Stephenson
Acclaimed Contributor

Re: send text file as an attachment

Elm will certainly work:

Your file, myletter, should look something like this:

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

This is some more text.

[include myfile2 application/octet-stream base64]

This is the end of my letter.

elm -s "My Subject" user@someplace.com < myletter

That will send myfile1 and myfile2 as attachments. I suspect the problem is that you have not created a .elm directory in the sender's home directory; the interactive version of elm will create that directory automatically but the command-line version will not.
If it ain't broke, I can fix that.
Dave La Mar
Honored Contributor
Solution

Re: send text file as an attachment

Anand -
Our shop uses mailx almost exclusively. Attached you will find a number of examples which include attachments.

Best regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
Rita C Workman
Honored Contributor

Re: send text file as an attachment

...and to go along with Clay's..here is yet another way to send a plain simple text file using the include statement...

[include myfile text/plain base64]

elm -s "the file" you@dot.com
Rita