MAIL question for HP-Unix O/S - The UNIX and Linux Forums

http://www.unix.com/how-do-i-send-email/4796-mail-question-hp-...

The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers > Answers to Frequently Asked Questions > How do I send email? User Name Password Remember Me?

google site

MAIL question for HP-Unix O/S
Forums Register Forum Rules Links Man Pages Albums FAQ Users Calendar Today's Posts

How do I send email? Learn how to send a UNIX or Linux email attachment from the command line.

Thread Tools 02-26-2002

Search this Thread

Display Modes #1

dsthompson
Registered User MAIL question for HP-Unix O/S

Join Date: Feb 2002 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts

Has anyone written a script to attached a text file when sending an email using the MAIL command? I wrote a Unix Script to email an end-user a text file. I want the file to be an attachment. I've tried the unix command uuencode but this seems to be for a binary file. My text file is garbage (binary) when it's opened from within the email. --------------------------------------------------------****** SAMPLE SCRIPT BELOW ****** --------------------------------------------------------uuencode $LG_TOP/bin/ARPSONIC.txt $LG_TOP/bin/SONIC.txt > $LG_TOP/bin/dst.tst to=dsthompson@upslogistics.com from=dsthompson@upslogistics.com cc=dsthompson@upslogistics.com echo 'To:'$to > $LG_TOP/bin/dst.tmp echo 'From:'$from >> $LG_TOP/bin/dst.tmp echo 'Cc:'$cc >> $LG_TOP/bin/dst.tmp echo 'Return-receipt: Yes' >> $LG_TOP/bin/dst.tmp echo 'Subject: UPS Logistics Files ' >> $LG_TOP/bin/dst.tmp echo 'Dear Customer' >> $LG_TOP/bin/dst.tmp echo ' '>> $LG_TOP/bin/dst.tmp echo 'Please find attached File' >> $LG_TOP/bin/dst.tmp echo ' '>> $LG_TOP/bin/dst.tmp echo 'Thank you'>> $LG_TOP/bin/dst.tmp echo ' '>> $LG_TOP/bin/dst.tmp echo 'Deborah S. Thompson'>> $LG_TOP/bin/dst.tmp cat $LG_TOP/bin/dst.tmp $LG_TOP/bin/dst.tst > $LG_TOP/bin/dst.tmp1

1 of 7

11/18/2011 2:16 PM

com/how-do-i-send-email/4796-mail-question-hp-.The UNIX and Linux Forums http://www.$cc mail $RECIPIENTS < $LG_TOP/bin/dst. Code: #! /usr/bin/ksh 2 of 7 11/18/2011 2:16 PM . This was to satisfy all of our customers at once.tmp1 Sponsored Links Remove advertisements 02-26-2002 #2 Perderabo Unix Daemon Join Date: Aug 2001 Location: Ashburn.MAIL question for HP-Unix O/S . Virginia Posts: 9.679 Thanks: 26 Thanked 206 Times in 139 Posts I had to write a script on HP-UX that would send an ascii file as a mime attachment but in such a way that a non mime mailer could read it...unix. Here it is... RECIPIENTS=$to.

txt -A attach. # # # # # # # # # # # # # # # # # # # # # # This script takes two ascii files and mails them. do case $opt in t) TO=$OPTARG ..txt file is but it will get mixed up with a ..The UNIX and Linux Forums http://www. then print -u2 "-t NAME is required" ((error=error+1)) fi 3 of 7 11/18/2011 2:16 PM ..txt are files...junk file. \?) print -u2 what is -${OPTARG}? ((error=error+1)) . esac done if [[ -z $TO ]] .com Here body..com/how-do-i-send-email/4796-mail-question-hp-.. The name of the attachment file is important since it will be sent as well as the contents. One file is the main body of the message. a) ADDRESS=$OPTARG . s) SUBJECT=$OPTARG . :) print -u2 $OPTARG need an argument ((error=error+1)) .unix.txt and attach.. b) BODY=$OPTARG . ((error=0)) while getopts ':t:a:b:A:s:' opt .MAIL question for HP-Unix O/S ..txt mimetool -t "Joe Blow" -a jblow@abc. A) ATTACHMENT=$OPTARG . The name of the body file isn't too important. A Microsoft OS uses the name to figure out what to do. The second file is sent as an ascii mime attachment. It knows what a . But everything is kept in ascii so that users with non-mime mail user agents can deal with it Options -t -a -b -s -A addressee address body subject attachment (required) (required) (required) (optional) (optional) -b body.

then print ."To: $TO <${ADDRESS}>" if [[ -n $SUBJECT ]] .'Subject:' $SUBJECT fi print . then print -u2 "-b $BODY is not a readable file" ((error=error+1)) fi if [[ -z $ATTACHMENT ]] .unix. ===' { print .0' print .MAIL question for HP-Unix O/S . then print -u2 "-b $ATTACHMENT is not a readable file" ((error=error+1)) fi if ((error)) .' This message is in MIME format.' BOUNDARY='\"$BOUNDARY\" print print . then print -u2 "error in parameter list. But if you can see this..com/how-do-i-send-email/4796-mail-question-hp-. do pwfield[index]=${pwentry%%${pwentry##*([!:])}} pwentry=${pwentry##*([!:]):} ((index=index+1)) done pwfield[index]=${pwentry} myname=${pwfield[4]%%. ' print .*} myaddr=${pwfield[0]} BOUNDARY='=== This is the boundary between parts of the message.'Content-Type: MULTIPART/MIXED."From: $myname <${myaddr}>" print . then print -u2 "-A ATTACHMENT is required" ((error=error+1)) fi if [[ ! -f $ATTACHMENT || ! -r $ATTACHMENT ]] ..' 4 of 7 11/18/2011 2:16 PM . then print -u2 "-b BODY is required" ((error=error+1)) fi if [[ ! -f $BODY || ! -r $BODY ]] .. then print -u2 "-a ADDRESS is required" ((error=error+1)) fi if [[ -z $BODY ]] .exiting" exit 1 fi pwentry=$(grep "^$(id -un):" /etc/passwd) ((index=0)) while [[ $pwentry = *:* ]] .. if [[ -z $ADDRESS ]] .'MIME-Version: 1.The UNIX and Linux Forums http://www.

'Content-Type: TEXT/PLAIN.. Sponsored Links Remove advertisements 03-19-2002 #3 skipper Guest Posts: n/a Bits: 0 [Banking] Great post. You shouldn't " print . print . 04-23-2002 at 08:39 AM.."--${BOUNDARY}--" } | /usr/lib/sendmail $ADDRESS exit 0 Last edited by Perderabo. charset=US-ASCII' print cat $BODY print print print ."--${BOUNDARY}" print ."--${BOUNDARY}" print .unix.'Content-Disposition: attachment..The UNIX and Linux Forums http://www.' ASCII and is designed to be somewhat readable with old ' print ." you aren't using a MIME aware mail program. name='${ATTACHMENT} print .' mail software. filename='${ATTACHMENT} print cat $ATTACHMENT print print .MAIL question for HP-Unix O/S . Thanks 03-26-2002 #4 5 of 7 11/18/2011 2:16 PM .com/how-do-i-send-email/4796-mail-question-hp-.' print print . Worked first time.'Content-Type: TEXT/PLAIN. charset=US-ASCII.' have too many problems because this message is entirely in' print .

com/how-do-i-send-email/4796-mail-question-hp-.com. Sponsored Links Remove advertisements « sending files as attachments | multiple attachments » More UNIX and Linux Forum Topics You Might Find Helpful Thread Question on SCP and Mail command mail question here I am not able to send mail form unix to other mail accounts. Posts: 1. You should share this on www.. Kelam_Magnus Registered User Join Date: Aug 2001 Location: DFW McKinney.069 Thanks: 0 Thanked 2 Times in 2 Posts Excellent work! This is better than using ELM even though it works. but is a little awkward.The UNIX and Linux Forums http://www. TX..MAIL question for HP-Unix O/S . Thanks for the great script. can not send mail from unix server to company/yahoo mail Mail question? Thread Starter chris1234 Forum UNIX for Dummies Questions & Answers Replies 9 Last Post 01-20-2008 03:54 PM 05-12-2006 03:42 PM 04-06-2006 09:31 AM lostinfaith UNIX for Dummies Questions & Answers 1 chinnigd UNIX for Dummies Questions & Answers 1 b5fnpct UNIX for Dummies Questions & Answers 5 11-22-2002 09:24 PM 10-15-2002 11:53 AM yxiao UNIX for Dummies Questions & Answers 2 6 of 7 11/18/2011 2:16 PM . They have a contest for the best scripts each month.unix.unixreview.

.Archive Top The UNIX and Linux Forums Content Copyright ©1993-2011. Language Translations Powered by Google vBCredits v1. Copyright ©2000 . The time now is 03:15 PM.The UNIX and Linux Forums http://www..2006.com/how-do-i-send-email/4796-mail-question-hp-.4 Copyright ©2007 . All Rights Reserved. Forum Operations by The UNIX and Linux Forums Powered by: vBulletin.The UNIX and Linux Forums . PixelFX Studios SEO by vBSEO 7 of 7 11/18/2011 2:16 PM .Learn UNIX and UNIX Commands .. All times are GMT -4. Jelsoft Enterprises Limited.Contact Us .MAIL question for HP-Unix O/S .2008.unix.

Sign up to vote on this title
UsefulNot useful