The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers > Answers to Frequently Asked Questions > How do I send email?
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


How do I send email? How do I send an mail attachment from the command line?


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Question on SCP and Mail command chris1234 UNIX for Dummies Questions & Answers 9 01-20-2008 11:54 AM
mail question here lostinfaith UNIX for Dummies Questions & Answers 1 05-12-2006 11:42 AM
I am not able to send mail form unix to other mail accounts. chinnigd UNIX for Dummies Questions & Answers 1 04-06-2006 05:31 AM
can not send mail from unix server to company/yahoo mail b5fnpct UNIX for Dummies Questions & Answers 5 11-22-2002 05:24 PM
Mail question? yxiao UNIX for Dummies Questions & Answers 2 10-15-2002 07:53 AM

 
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-26-2002
Registered User
 

Join Date: Feb 2002
Posts: 1
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
MAIL question for HP-Unix O/S

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
RECIPIENTS=$to,$cc
mail $RECIPIENTS < $LG_TOP/bin/dst.tmp1
Forum Sponsor
  #2 (permalink)  
Old 02-26-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,207
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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. This was to satisfy all of our customers at once. Here it is...
Code:
#! /usr/bin/ksh


#
#  This script takes two ascii files and mails them.  One file is
#  the main body of the message.  The second file is sent as an ascii
#  mime attachment.  But everything is kept in ascii so that users with
#  non-mime mail user agents can deal with it
#
#
#  Options 
#
#  -t addressee  (required)
#  -a address    (required)
#  -b body       (required)
#  -s subject    (optional)
#  -A attachment (optional)
#
#  mimetool -t "Joe Blow" -a jblow@abc.com  -b body.txt  -A attach.txt
#
#  Here body.txt and attach.txt are files.  The name of the body file
#  isn't too important.  The name of the attachment file is important 
#  since it will be sent as well as the contents.  A Microsoft OS uses
#  the name to figure out what to do.  It knows what a .txt file is but
#  it will get mixed up with a .junk file.  

((error=0))
while getopts ':t:a:b:A:s:' opt ; do
	case $opt in
	t)
		TO=$OPTARG
		;;
	a)
		ADDRESS=$OPTARG
		;;
	b)
		BODY=$OPTARG
		;;
	A)
		ATTACHMENT=$OPTARG
		;;
	s)
		SUBJECT=$OPTARG
		;;
	\?)
		print -u2 what is -${OPTARG}?
		((error=error+1))
		;;
	:)
		print -u2 $OPTARG need an argument
		((error=error+1))
		;;
	esac
done

if [[ -z $TO ]] ; then
	print -u2 "-t NAME is required"
	((error=error+1))
fi

if [[ -z $ADDRESS ]] ; then
	print -u2 "-a ADDRESS is required"
	((error=error+1))
fi

if [[ -z $BODY ]] ; then
	print -u2 "-b BODY is required"
	((error=error+1))
fi

if [[ ! -f $BODY ||  ! -r $BODY ]] ; then
	print -u2 "-b $BODY is not a readable file"
	((error=error+1))
fi

if [[ -z $ATTACHMENT ]] ; then
	print -u2 "-A ATTACHMENT is required"
	((error=error+1))
fi

if [[ ! -f $ATTACHMENT ||  ! -r $ATTACHMENT ]] ; then
	print -u2 "-b $ATTACHMENT is not a readable file"
	((error=error+1))
fi

if ((error)) ; then
	print -u2 "error in parameter list...exiting"
	exit 1
fi


pwentry=$(grep "^$(id -un):" /etc/passwd)
((index=0))
while [[ $pwentry = *:* ]] ; do
	pwfield[index]=${pwentry%%${pwentry##*([!:])}}
	pwentry=${pwentry##*([!:]):}
	((index=index+1))
done
pwfield[index]=${pwentry}
myname=${pwfield[4]%%,*}
myaddr=${pwfield[0]}



BOUNDARY='=== This is the boundary between parts of the message. ==='

{
print -  "From: $myname <${myaddr}>"
print -  "To: $TO <${ADDRESS}>"
if [[ -n $SUBJECT ]] ; then
	print -  'Subject:' $SUBJECT
fi
print -  'MIME-Version: 1.0'
print -  'Content-Type: MULTIPART/MIXED; '
print -  '    BOUNDARY='\"$BOUNDARY\"
print - 
print -  '        This message is in MIME format.  But if you can see this,'
print -  "        you aren't using a MIME aware mail program.  You shouldn't "
print -  '        have too many problems because this message is entirely in'
print -  '        ASCII and is designed to be somewhat readable with old '
print -  '        mail software.'
print - 
print -  "--${BOUNDARY}"
print -  'Content-Type: TEXT/PLAIN; charset=US-ASCII'
print - 
cat $BODY
print - 
print - 
print -  "--${BOUNDARY}"
print -  'Content-Type: TEXT/PLAIN; charset=US-ASCII; name='${ATTACHMENT}
print -  'Content-Disposition: attachment;   filename='${ATTACHMENT}
print - 
cat $ATTACHMENT
print - 
print -  "--${BOUNDARY}--"
} | /usr/lib/sendmail $ADDRESS

exit 0

Last edited by Perderabo : 04-23-2002 at 04:39 AM.
  #3 (permalink)  
Old 03-19-2002
skipper
 

Posts: n/a
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Thumbs up

Great post. Worked first time. Thanks
  #4 (permalink)  
Old 03-26-2002
Kelam_Magnus's Avatar
Unix does a body good.
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Excellent work! This is better than using ELM even though it works, but is a little awkward.

Thanks for the great script.

You should share this on www.unixreview.com. They have a contest for the best scripts each month.

Google UNIX.COM
 



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 06:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102