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 08:39 AM..
Hi, all,
I use mail to send a file to my email account as follow:
mail -v user@address.com < /user/text
however, I received is a blank email without any content in it. How can I set up config correctly in the Solaris box? Any suggests so can send the whole text? Thank you in advance!
Yun (2 Replies)
hi, Gurus,
I need some help with sending mail out from my UNIX server:
It is running Solaris 2.6 and the sendmail version is 8.8.
Output of :/usr/lib/sendmail -d0.1 -bt < /dev/null
Version 8.8.8+Sun
Compiled with: LOG MATCHGECOS MIME7TO8 MIME8TO7 NAMED_BIND NDBM NETINET
... (5 Replies)
Hi
In the company I work for one guy ask me this question:
Can you have several mail servers managing the same domain, in the same lan?
My first answer was that it's not possible cause each mail server must not share a domain, but .... I'm not sure.
Can anyone more enlightened than me,... (1 Reply)
Using Mailx command i.e
mailx -s "subject" chinni@hotmail.com < \tmp\chin
this command executed sucessfully but not able to receive the mail in chinni@hotmail.com
please help. (1 Reply)
Hi
Could someone help me with the details on how to send an attachment through mail in unix.
I have an html file in my unix machine and I want this to be send to some mail id, plese help with the steps.
Regards
Ajay (2 Replies)
Hi.
I am running a script on solaris 10 and mailing it to my personal email.
the script is ran as user xxx, And i have edited the crontab for user xxx to run the script and mail it to my email account.
/network_check.sh | /usr/bin/mailx -s "Network Test" k454@hotmail.com
the sript... (2 Replies)
Hi,
I need to send email notifications from Unix/Linux box to users using mailx.
In these Unix/Linux boxes mail is not configured however we are having mail server configured in our LAN.
Could you please provide instructions to configure relay in these boxes so that we can relay our mails... (3 Replies)
We have configured our mail unix server and can send out emails automatically from applications running on unix to different people in our company as well as outside our company. However there is an outside client who is not receiving these emails because the settings on their mail server cannot... (4 Replies)
Hi all,
I want to send a mail for my business needs from outlook account to an unix server (HP-UX) but I don't send any mail. While I can send from the unix server to my outlook account, I can't send from outlook to unix.
How can I achieve this ? How can I send a mail from my outlook or other... (2 Replies)