Discussion:
mailx / sendmail command
(too old to reply)
yy4 via DBMonster.com
2006-07-17 06:55:00 UTC
Permalink
Can anyone provide the command how to send a text file as a attachment with a
proper subject using mailx or sendmail command in UNIX.

Note: I am using HP-UX OS. The file send should be the attachment, not in the
message body. In addition, I need to put in the mail subject as well.
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/informix/200607/1
Jonathan Leffler
2006-07-17 07:15:39 UTC
Permalink
Post by yy4 via DBMonster.com
Can anyone provide the command how to send a text file as a attachment with a
proper subject using mailx or sendmail command in UNIX.
Note: I am using HP-UX OS. The file send should be the attachment, not in the
message body. In addition, I need to put in the mail subject as well.
Unix questions on the Informix list? Well, sometimes it'll work.

I suggest asking on a Unix list instead. Offhand, I certainly don't know.
--
Jonathan Leffler #include <disclaimer.h>
Email: ***@earthlink.net, ***@us.ibm.com
Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/
knliew
2006-07-17 10:37:31 UTC
Permalink
( cat your_text_msg ; uuencode attachment1 attachment2 ) | mailx -s
Post by yy4 via DBMonster.com
Can anyone provide the command how to send a text file as a attachment with a
proper subject using mailx or sendmail command in UNIX.
Note: I am using HP-UX OS. The file send should be the attachment, not in the
message body. In addition, I need to put in the mail subject as well.
Rob Konikoff
2006-07-17 11:17:02 UTC
Permalink
Yep... we do it all the time... it's a pain in the @!@#$%^!!^^!@#$

However, that's the deliver option the customer wants.

You have several options. It depends on whether you want to include a
message in the body as well.

(cat message.txt ; uuencode ${TMP}/attachment attach.txt ) | mailx -m -s
"Subject of message" < ${email_addresses}

Conditionals: You must use proper email addresses for which you have host
resolution (or DNS enabled), the message.txt and the ${TMP}/attachment must
go through the UNIX to DOS conversion, and the whole thing should be tested
at the recipients side.

I like uuencode. However, I'm a dinosaur. Oh, and I LOVE HP-UX!

You must have a mail client at the other end with the proper configuration
to translate uuencode. Microsoft Outlook automatic defaults work well here
if you echange, pop or ldap. However, if the destination is a web mail
client, you'll get gobblety gook.

Rob


-----Original Message-----
From: informix-list-***@iiug.org [mailto:informix-list-***@iiug.org]
On Behalf Of yy4 via DBMonster.com
Sent: Monday, July 17, 2006 2:55 AM
To: informix-***@iiug.org
Subject: mailx / sendmail command

Can anyone provide the command how to send a text file as a attachment with
a
proper subject using mailx or sendmail command in UNIX.

Note: I am using HP-UX OS. The file send should be the attachment, not in
the
message body. In addition, I need to put in the mail subject as well.
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/informix/200607/1
Carsten Haese
2006-07-17 12:15:14 UTC
Permalink
Post by Rob Konikoff
However, that's the deliver option the customer wants.
You have several options. It depends on whether you want to include a
message in the body as well.
(cat message.txt ; uuencode ${TMP}/attachment attach.txt ) | mailx -m -s
"Subject of message" < ${email_addresses}
Conditionals: You must use proper email addresses for which you have host
resolution (or DNS enabled), the message.txt and the ${TMP}/attachment must
go through the UNIX to DOS conversion, and the whole thing should be tested
at the recipients side.
I like uuencode. However, I'm a dinosaur. Oh, and I LOVE HP-UX!
You must have a mail client at the other end with the proper configuration
to translate uuencode. Microsoft Outlook automatic defaults work well here
if you echange, pop or ldap. However, if the destination is a web mail
client, you'll get gobblety gook.
The original poster said the file is plain text. In that case it is
nearly trivial to build a MIME message ("manually" add MIME headers and
MIME boundaries, details left as an exercise for the reader), which
should be less likely to cause problems in the mail client.
--
Carsten Haese | Phone: (419) 861-3331
Software Engineer | Direct Line: (419) 794-2531
Unique Systems, Inc. | FAX: (419) 893-2840
1687 Woodlands Drive | Cell: (419) 343-7045
Maumee, OH 43537 | Email: ***@uniqsys.com
Gentsch, Sam
2006-07-17 13:24:40 UTC
Permalink
Post by yy4 via DBMonster.com
Can anyone provide the command how to send a text file as a
attachment with a
Post by yy4 via DBMonster.com
proper subject using mailx or sendmail command in UNIX.
The only way I know:
uuencode your_filename your_filename |mailx -s "your subject here"
***@email.com
Adam Tauno Williams
2006-07-17 13:45:05 UTC
Permalink
Post by yy4 via DBMonster.com
Post by yy4 via DBMonster.com
an anyone provide the command how to send a text file as a
attachment with a
Post by yy4 via DBMonster.com
proper subject using mailx or sendmail command in UNIX.
uuencode your_filename your_filename |mailx -s "your subject here"
I don't think mailx has any support for attachments. Does your OS have
the "nail" command?
Rob Konikoff
2006-07-17 14:28:13 UTC
Permalink
Oops... take out the "<" syntax... use that only if you want to put your
message body there...

It should be:
(cat message.txt ; uuencode ${TMP}/attachment attach.txt ) | mailx -m -s
"Subject of message" ${email_addresses}

Rob
-----Original Message-----
From: informix-list-***@iiug.org [mailto:informix-list-***@iiug.org]
On Behalf Of Rob Konikoff
Sent: Monday, July 17, 2006 7:17 AM
To: 'yy4 via DBMonster.com'; informix-***@iiug.org
Subject: RE: mailx / sendmail command

Yep... we do it all the time... it's a pain in the @!@#$%^!!^^!@#$

However, that's the deliver option the customer wants.

You have several options. It depends on whether you want to include a
message in the body as well.

(cat message.txt ; uuencode ${TMP}/attachment attach.txt ) | mailx -m -s
"Subject of message" < ${email_addresses}

Conditionals: You must use proper email addresses for which you have host
resolution (or DNS enabled), the message.txt and the ${TMP}/attachment must
go through the UNIX to DOS conversion, and the whole thing should be tested
at the recipients side.

I like uuencode. However, I'm a dinosaur. Oh, and I LOVE HP-UX!

You must have a mail client at the other end with the proper configuration
to translate uuencode. Microsoft Outlook automatic defaults work well here
if you echange, pop or ldap. However, if the destination is a web mail
client, you'll get gobblety gook.

Rob


-----Original Message-----
From: informix-list-***@iiug.org [mailto:informix-list-***@iiug.org]
On Behalf Of yy4 via DBMonster.com
Sent: Monday, July 17, 2006 2:55 AM
To: informix-***@iiug.org
Subject: mailx / sendmail command

Can anyone provide the command how to send a text file as a attachment with
a
proper subject using mailx or sendmail command in UNIX.

Note: I am using HP-UX OS. The file send should be the attachment, not in
the
message body. In addition, I need to put in the mail subject as well.
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/informix/200607/1
bozon
2006-07-17 15:03:55 UTC
Permalink
Thanks, for correcting that I was wondering about that.
Post by Rob Konikoff
Oops... take out the "<" syntax... use that only if you want to put your
message body there...
(cat message.txt ; uuencode ${TMP}/attachment attach.txt ) | mailx -m -s
"Subject of message" ${email_addresses}
Rob
-----Original Message-----
On Behalf Of Rob Konikoff
Sent: Monday, July 17, 2006 7:17 AM
Subject: RE: mailx / sendmail command
However, that's the deliver option the customer wants.
You have several options. It depends on whether you want to include a
message in the body as well.
(cat message.txt ; uuencode ${TMP}/attachment attach.txt ) | mailx -m -s
"Subject of message" < ${email_addresses}
Conditionals: You must use proper email addresses for which you have host
resolution (or DNS enabled), the message.txt and the ${TMP}/attachment must
go through the UNIX to DOS conversion, and the whole thing should be tested
at the recipients side.
I like uuencode. However, I'm a dinosaur. Oh, and I LOVE HP-UX!
You must have a mail client at the other end with the proper configuration
to translate uuencode. Microsoft Outlook automatic defaults work well here
if you echange, pop or ldap. However, if the destination is a web mail
client, you'll get gobblety gook.
Rob
-----Original Message-----
On Behalf Of yy4 via DBMonster.com
Sent: Monday, July 17, 2006 2:55 AM
Subject: mailx / sendmail command
Can anyone provide the command how to send a text file as a attachment with
a
proper subject using mailx or sendmail command in UNIX.
Note: I am using HP-UX OS. The file send should be the attachment, not in
the
message body. In addition, I need to put in the mail subject as well.
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/informix/200607/1
_______________________________________________
Informix-list mailing list
http://www.iiug.org/mailman/listinfo/informix-list
_______________________________________________
Informix-list mailing list
http://www.iiug.org/mailman/listinfo/informix-list
Mark Denham
2006-07-17 15:04:20 UTC
Permalink
Here you go. This will send the file as an attachment. The variable msg is
used in the subject.

function techMail {

endDate=$(date)
command=${1}
logfile=${2}
typeset -i status=${3}
typeset -i2 severity=4
host=$(hostname)
user=${LOGNAME:-unknown}

case ${status} in
0) msg="Completed Successfully"
severity=1
;;
111) msg="Completed with Warnings"
severity=2
;;
*) msg="Completed with FAILURES"
severity=4
;;
esac

cat >> ${logfile} <<EOF

##############################################################################
${msg} on ${endDate}
##############################################################################

EOF

#
# REMEMBER its a bitwize comparison!!! Also remember that shell treats
0 as
# TRUE~).
#

[ $((${severity} & ${MSG_SEVERITY})) -eq 0 ] && return 0

/usr/sbin/sendmail ${MAILTO} <<EOF
From: ${user}@${host}
To: ${MAILTO}
Subject: CRON(${command}): ${msg}.
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="DMW.Boundary.605592468"

--DMW.Boundary.605592468
Content-Type: application/octet-stream; name="$logfile"
Content-Disposition: attachment; filename="$logfile"
Content-Transfer-Encoding: 7bit

$(cat ${logfile})

--DMW.Boundary.605592468--

EOF

return ${?}
}
Post by yy4 via DBMonster.com
Can anyone provide the command how to send a text file as a attachment with a
proper subject using mailx or sendmail command in UNIX.
Note: I am using HP-UX OS. The file send should be the attachment, not in the
message body. In addition, I need to put in the mail subject as well.
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/informix/200607/1
_______________________________________________
Informix-list mailing list
http://www.iiug.org/mailman/listinfo/informix-list
bozon
2006-07-17 15:23:32 UTC
Permalink
Searching on google groups (using: mailx sending attachments )

Choosing:
http://groups.google.com/group/comp.unix.aix/browse_frm/thread/e37e3e2937bd9da2/83e9c039d82df66e?lnk=st&q=mailx+sending+attachments&rnum=4&hl=en#83e9c039d82df66e

I get a reference to the following shell script which looks worked out
well and which only uuencodes if it has to (because you are sending
binary files, specified with the -b option)



#set +x
#
# jail -> shell script for sending mime email enclosures from command
line
#
# Usage : jail [options] email-address file-to-be-sent
# $1 $2
#
# John Roebuck - 11/08/97
#
# John Roebuck - 29/01/98 - Add options to allow optional subject and
urgent.
# John Roebuck - 18/03/98 - Get Hostname of machine and user.
# John Roebuck - 26/05/98 - Allow multiple files to be sent.
# John Roebuck - 11/12/98 - Remove all MTMS options and requirements,
# also added -v for verbose (debug) sendmail
option.
# John Roebuck - 17/12/98 - Added -b option of uuencoding binary files.
# John Roebuck - 22/12/98 - Added -r option of delivery receipt
required.

version="jail 1.4 by John Roebuck 17/12/98"

#
# Get command line options
#
bflag=0
rflag=0
sflag=0
uflag=0
vflag=0

while getopts brs:uv name
do
case $name in
b) bflag=1;;
r) rflag=1;;
s) sflag=1
sval="$OPTARG";;
u) uflag=1;;
v) vflag=1;;
#
# Display syntax if ? passed as an option in the command line
#
?) echo " "
echo "Usage : jail [options] email-address files-to-be-set"
echo " "
echo " options are -b for binary files"
echo " -r delivery receipt required"
echo " -s (subject of mail message)"
echo " -u Urgent"
echo " -v Verbose sendmail (debug)"
echo " ("$version")"
echo " "
exit 2;;
esac
done

#
# Set urgent flag to 1 if urgent option is found
#
if [ $uflag = 1 ]; then urgent="urgent"
else urgent="normal"
fi

#
# Include subject from command line if subject option is found
#
if [ $sflag = 1 ]; then subject=$sval
else subject=" "
fi

shift $(($OPTIND -1))

#
# Display syntax if less than 2 command line parameters are found
# after the command line options. Require email address and 1 file
# as a minimum.
#
if [ $# -lt 2 ]
then echo " "
echo "Usage : jail [options] email-address files-to-be-sent"
echo " "
echo " options are -b for binary files"
echo " -r delivery receipt required"
echo " -s (subject of mail message)"
echo " -u Urgent"
echo " -v Verbose sendmail (debug)"
echo " ("$version")"
echo " "
exit
fi

#
# set -f stops * being expanded within the shell script. (ksh option)
#
set -f

#
# Now get the send to email address
#
sendto=$1
shift

#
# Find out how many files to send as enclosures in this email message
#
attno=$#
if [ $attno = 1 ]; then attmess="enclosure"
else attmess="enclosures"
fi

#
# Format the variable $now as "Friday 18 December 1998 16:22"
#
xday=`date +%a`
xdayno=`date +%d`
xmonth=`date +%b`
xyear=`date +%Y`
xtime=`date +%H:%M:%S`
now=$xday", "$xdayno" "$xmonth" "$xyear" "$xtime

#
# Create message boundary number based on process id
#
boundary=JPR$$

#
# Create message id number based on date and process id
#
messid=`date +%d%m%y`$$

#
# Create temporary file based on date time and process id
#
tempfile=/tmp/jail-`date +%d%m%y%H%M%S`$$
touch $tempfile

#
# Get sender details eg user name and description, machine hostname
#
# sender login is the login name of the current user account
#
senderlogin=`whoami`
#
# Domain is taken from the domain field in /etc/resolv.conf file
#
senderdomain=`grep domain /etc/resolv.conf | cut -f2`
#
# Sender address is login name @ machine hostname . domain
#
senderaddress=$senderlogin"@"`hostname`"."$senderdomain
#
# Sender name is taken from the login name description field in
/etc/passwd
#
sendername=`grep $senderlogin /etc/passwd |cut -d: -f5`

#
# Create header part of email file
#

echo "From: \""$sendername"\" <"$senderaddress">" >> $tempfile
echo "To: "$sendto >> $tempfile
echo "Date: "$now >> $tempfile
echo "Mime-Version: 1.0 "$version >> $tempfile
echo "Content-Type: Multipart/Mixed;
boundary=Message-Boundary-"$boundary >> $tempfile
echo "Subject: "$subject>> $tempfile

#
# Is a delivery receipt required ?
#
if [ $rflag = 1 ]; then
echo "Return-Receipt-To: \""$sendername"\" <"$senderaddress">" >>
$tempfile
fi

echo "Priority: "$urgent >> $tempfile
echo "Message-Id: <"$messid"."$senderdomain >> $tempfile
echo "Status: RO" >> $tempfile
echo "" >> $tempfile
echo "" >> $tempfile
echo "--Message-Boundary-"$boundary >> $tempfile
echo "Content-type: text/plain; charset=US-ASCII" >> $tempfile
echo "Content-transfer-encoding: 7BIT" >> $tempfile
echo "Content-description: Read Me First" >> $tempfile
echo "" >> $tempfile
echo "" >> $tempfile

#
# Create mail message body part of email file
#

echo "Hello" >> $tempfile
echo "" >> $tempfile
echo "Please find "$attno" '"$attmess"' to this email message :- " >>
$tempfile
echo "" >> $tempfile

#
# Generate file information for each enclosure. The information is in
the
# format : File name 1 aix.doc
# Produced on 16 Dec at 18:59
# File size 33469 bytes.
#
messno=0
while [ $attno -gt $messno ]
do

messno=`expr $messno + 1`
filename[$messno]=$1
shift

report1="File name "$messno" "${filename[$messno]}
report2=`ls -l "${filename[$messno]}" |awk '{print "" "Produced on
"$6 " " $7 " at " $8 "" }'`
report3=`ls -l "${filename[$messno]}" |awk '{print "" "File size
"$5" bytes." "" }'`

echo "$report1" >> $tempfile
echo "$report2" >> $tempfile
echo "$report3" >> $tempfile

echo "" >> $tempfile

done

echo "" >> $tempfile
echo "" >> $tempfile
echo "Regards "$sendername" ("$senderaddress")" >> $tempfile
echo "" >> $tempfile

#
# For each file, create enclosure for the file.
#
messno=0
while [ $attno -gt $messno ]
do

messno=`expr $messno + 1`

#
# Check from command line if files are ascii or binary
#
if [ $bflag = 0 ]; then

#
# Add extra chr$ to ascii files for unix to dos conversion. This
# means reading in each line of the text file and writing it out to
# the temp file with a charage return character added to the end of
# each line.
# Unforntunately ksh read will ignore leading spaces at the beginning
# of each line.
#
echo "--Message-Boundary-"$boundary >> $tempfile
echo "Content-type: Application/Octet-Stream;
name=${filename[$messno]}; type=Text" >> $tempfile
echo "Content-description: attachment; filename=${filename[$messno]}"
Post by yy4 via DBMonster.com
$tempfile
echo "" >> $tempfile

{
while read line_data
do
echo "$line_data""
" >> $tempfile
done } < ${filename[$messno]}

else

#
# uuencode binary mail
#
echo "--Message-Boundary-"$boundary >> $tempfile
echo "Content-type: Application/Octet-stream;
name=${filename[$messno]}; type=Binary" >> $tempfile
echo "Content-disposition: attachment; filename=${filename[$messno]}"
Post by yy4 via DBMonster.com
$tempfile
echo "Content-transfer-encoding: X-UUencode" >> $tempfile
echo "" >> $tempfile

uuencode ${filename[$messno]} ${filename[$messno]} >> $tempfile

fi
done

#
# Send email message straight to sendmail. Use -v option if debug
# option has been set at the command line.
#
if [ $vflag = 1 ]; then /usr/lib/sendmail -v $sendto < $tempfile
else /usr/lib/sendmail $sendto < $tempfile
fi

#
# Remove temp file
#
rm $tempfile
Post by yy4 via DBMonster.com
Can anyone provide the command how to send a text file as a attachment with a
proper subject using mailx or sendmail command in UNIX.
Note: I am using HP-UX OS. The file send should be the attachment, not in the
message body. In addition, I need to put in the mail subject as well.
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/informix/200607/1
Continue reading on narkive:
Search results for 'mailx / sendmail command' (Questions and Answers)
8
replies
Difference Between Unix and Linux commands?
started 2008-03-26 04:56:03 UTC
software
Loading...