Finally, the summary...
ORIGINAL MESSAGE:
>I've never really used mailx and now I'm stuck with a problem.
>I've read the archives but can't find exactly what I need
>
>We have Solaris 2.5 & 2.5.1 & 2.6
>
>I'm trying to do the following:
>1. to send a file as an attachment to an internet address via mailx.
> (This will be eventually be incorporated in a shell script.)
>2. The receiver on the other end has a PC (probably win'95) and must be able to read the attachment.
>
>How can I do this?
> I want to send a text file that's generated from our mainframe.
> (It has simple formatting like spaces & line ends)
> I don't want to include this info in the message body itself, it has to be an attachment.
> (we will most probably be sending up to a 1000 of these messages a week to different clients)
*********************************************************************************
There sure are many ways to kill a cat. :-)
Many people didn't think it could be done with mailx
Well... what I'll be doing is based on what Jim Harmon sent:
From: Jim Harmon jharmon@telecnnct.com
The method would be to send a file of the type you intend to yourself as
an attachment manually with a WEB/MIME enabled mailer (like netscape).
When you get the file back, use the "view file source" option to see the
atachement header syntax.
Once you know what the atachement header (and FOOTER) look like, you can
write a script to prepend/append the header/footer to your generated
report, and then " << EOF" the entire thing to your mailx line.
I'll be creating my own header, putting it all together and submitting it directly to sendmail -t.
For those of you who asked for a summary, I'm also included all the other suggestions.
I didn't try any of these, because I decided against installing yet
another 3rd party product that makes maintenance & upgrading hell :-)
but I appreciated all the responses.
=======================================================================
mpack or metamail
Either of these can operate from a shell script and generate
attachments in RFC-822 MIME format that any sane PC e-mail client will be
able to read.
mpack/munpack MIME equivalent of uuencode/uudecode,
free from ftp://ftp.andrew.cmu.edu/pub/mpack/.
Part of readme:
Mpack and munpack are utilities for encoding and decoding
(respectively) binary files in MIME (Multipurpose Internet Mail
Extensions) format mail messages. For compatibility with older forms
of transferring binary files, the munpack program can also decode
messages in split-uuencoded format. The Macintosh version can also
decode messages in split-BinHex format.
Versions are included for unix, pc, os2, mac, amiga and archimedes
systems.
metamail Suite of MIME encode/decode viewing tools,
free from ftp://thumper.bellcore.com/pub/nsb/.
=======================================================================
mutt
It's a character-based mailer that can do MIME attachements.
"mutt", which is a successor to Elm (develop on Elm has been stagnant for ~5 years)
and which does support this. You can find it via
http://www.cs.hmc.edu/~me/mutt/index.html
=======================================================================
Pine
ftp://ftp.cac.washington.edu/pine
=======================================================================
mmencode
a command-line mime en/de-coder.
=======================================================================
uuencode
Some PC apps understand uuencoded data in the body of the message to be
an attachment.
There are PC ports of it eg uuxx. (supports uuencode, binhex, and one
other encoding tactic)
=======================================================================
Write a shell script something like this:
...
mailx whoever@wang.com << EOF
This is a file I want to send to the PC:
~r filename
EOF
...
comment: this of course copies the actual file into the body of the message (not an attachment)
=======================================================================
Metasend
From: Thomas Anders anders@hmi.de
I always use 'metasend' for this -- works like a charm in scripts.
It's a csh script itself. I attached it and its manpage for your
convenience.
METASEND SCRIPT:
--------------------------
#!/bin/csh -fb
# (The "-fb" might need to be changed to "-f" on some systems)
#
# Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
#
# Permission to use, copy, modify, and distribute this material
# for any purpose and without fee is hereby granted, provided
# that the above copyright notice and this permission notice
# appear in all copies, and that the name of Bellcore not be
# used in advertising or publicity pertaining to this
# material without the specific, prior written permission
# of an authorized representative of Bellcore. BELLCORE
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
# OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS",
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
#
if (! $?METAMAIL_TMPDIR) then
set METAMAIL_TMPDIR=/tmp
endif
set hname = `hostname`
set idctr=0
set MustDelete=0
set batchmode=0
set multipart = 1
if ($?SPLITSIZE) then
set splitsize=$SPLITSIZE
else
set splitsize = 100000
endif
set outputfile = ""
set multipartsubtype = "mixed"
set cdescrip = "An object packed by metasend"
set isentity=0
set newid=`date | tr " :" "__"`
set cid="<${newid}_$idctr@${hname}>"
@ idctr++
while ($#argv > 0)
switch ("$1")
case "-S":
shift
if ($#argv == 0) then
echo "-S requires a following argument, the SPLIT threshhold"
exit -1
endif
set splitsize=$1
shift
breaksw
case "-b":
# Batch mode -- ALL args must be on command line
set batchmode = 1
shift
breaksw
case "-c":
shift
if ($#argv == 0) then
echo "-c requires a following argument, the CC address"
exit -1
endif
set cc="$1"
shift
breaksw
case "-i":
shift
if ($#argv == 0) then
echo "-i requires a following argument, the Content-ID value"
exit -1
endif
set cid=$1
shift
breaksw
case "-I":
shift
if ($#argv == 0) then
echo "-I requires a following argument, the multipart Content-ID value"
exit -1
endif
set multicid=$1
shift
breaksw
case "-s":
shift
if ($#argv == 0) then
echo "-s requires a following argument, the SUBJECT"
exit -1
endif
set subject="$1"
shift
breaksw
case "-t":
shift
if ($#argv == 0) then
echo "-t requires a following argument, the TO address"
exit -1
endif
set to="$1"
shift
breaksw
case "-F":
shift
if ($#argv == 0) then
echo "-F requires a following argument, the FROM address"
exit -1
endif
set from="$1"
shift
breaksw
case "-P":
shift
if ($#argv == 0) then
echo "-P requires a following argument, the preamble file name"
exit -1
endif
set preamblefile="$1"
shift
breaksw
case "-e":
shift
if ($#argv == 0) then
echo "-e requires a following argument, the ENCODING value"
exit -1
endif
set encode=$1
if ($encode == "base64") then
set encodingprog = "mimencode -b"
else if ($encode == "x-uue") then
set encodingprog = "uuencode mail-body"
else if ($encode == "7bit") then
set encodingprog = cat
else
set encodingprog = "mimencode -q"
set encode = "quoted-printable"
endif
shift
breaksw
case "-f":
shift
if ($#argv == 0) then
echo "-f requires a following argument, the DATA FILE"
exit -1
endif
set datafile=$1
if (! -e $datafile) then
echo The file $datafile does not exist.
exit -1
endif
shift
breaksw
case "-m":
shift
if ($#argv == 0) then
echo "-m requires a following argument, the MIME CONTENT-TYPE"
exit -1
endif
# set ctyperaw = $1
# set ctype=`echo $ctyperaw | tr \" \'`
set ctype = "$1"
if (`echo $ctype | grep /` == "") then
echo "Invalid content-type specified"
exit -1
endif
shift
breaksw
case "-o":
shift
if ($#argv == 0) then
echo "-o requires a following argument, the output file name"
exit -1
endif
set outputfile="$1"
shift
breaksw
case "-/":
shift
if ($#argv == 0) then
echo "-/ requires a following argument, the multipart subtype"
exit -1
endif
set multipartsubtype="$1"
shift
breaksw
case "-D":
shift
if ($#argv == 0) then
echo "-D requires a following argument, the Content-Description value"
exit -1
endif
set cdescrip="$1"
shift
breaksw
case "-E":
set isentity=1
shift
breaksw
case "-z":
set MustDelete=1
shift
breaksw
case "-n":
if ($isentity) then
if (! $?encode) then
set encode=7bit
set encodingprog=cat
endif
if (! $?ctype) then
set ctype=bogus
# Never used
endif
if ( ! $?datafile) then
echo One part is incomplete -- each part needs at least -f and -E
exit -1
endif
else
if ( ! $?ctype || ! $?datafile) then
echo One part is incomplete -- each part needs at least -f and -m
exit -1
endif
endif
if (! $?encode) then
if ("$ctype" =~ text*) then
set encodingprog = "mimencode -q"
set encode = "quoted-printable"
else
set encode = base64
set encodingprog = "mimencode -b"
endif
endif
set ctype${multipart} = "$ctype"
set datafile${multipart} = $datafile
set encode${multipart} = $encode
set cdescrip${multipart} = "$cdescrip"
set cid${multipart} = "$cid"
set isentity${multipart} = $isentity
set encodingprog${multipart} = "$encodingprog"
unset ctype
unset datafile
unset encode
unset encodingprog
set newid=`date | tr " :" "__"`
set cid="<${newid}_$idctr@${hname}>"
@ idctr++
set cdescrip = "An object packed by metasend"
set isentity=0
@ multipart++
shift
breaksw
default:
echo UNRECOGNIZED METASEND OPTION: $1
exit -1
endsw
end
if ($batchmode == 0) then
if (! $?to) then
echo -n "To: "
set to = $<
endif
if (! $?subject) then
echo -n "Subject: "
set subject = $<
endif
if (! $?cc) then
echo -n "CC: "
set cc = $<
endif
anotherpart:
if (! $?ctype) then
echo -n "Content-type: "
# set ctyperaw = $<
# set ctype=`echo $ctyperaw | tr \" \'`
set ctype = "$<"
endif
if (`echo $ctype | grep /` == "") then
echo "Invalid content-type specified"
unset ctype
goto anotherpart
endif
# if ($ctype != $ctyperaw) echo Double quotes not allowed, using $ctype
if (! $?datafile) then
getfile:
echo -n "Name of file containing $ctype data: "
set datafile = $<
if (! -e $datafile) then
echo The file $datafile does not exist.
goto getfile
endif
endif
if (! $?encode) then
retry:
echo "Do you want to encode this data for sending through the mail?"
echo " 1 -- No, it is already in 7 bit ASCII"
echo " 2 -- Yes, encode in base64 (most efficient)"
echo " 3 -- Yes, encode in quoted-printable (less efficient, more readable)"
echo " 4 -- Yes, encode it using uuencode (not standard, being phased out)"
set encode=$<
switch ("$encode")
case 1:
set encodingprog = cat
set encode = 7bit
breaksw
case 2:
set encodingprog = "mimencode -b"
set encode = base64
breaksw
case 3:
set encodingprog = "mimencode -q"
set encode = quoted-printable
breaksw
case 4:
set encodingprog = "uuencode $datafile"
set encode = x-uue
breaksw
default:
echo Unrecognized answer, please try again.
goto retry
endsw
endif
echo -n "Do you want to include another file too (y/n) [n] ? "
set ans=$<
if ("$ans" =~ y*) then
set ctype${multipart} = "$ctype"
set datafile${multipart} = $datafile
set encode${multipart} = $encode
set encodingprog${multipart} = "$encodingprog"
set cdescrip${multipart} = "$cdescrip"
set cid${multipart} = "$cid"
set isentity${multipart} = $isentity
set cdescrip = "An object packed by metasend"
set isentity=0
unset ctype
unset datafile
unset encode
unset encodingprog
set newid=`date | tr " :" "__"`
set cid="<${newid}_$idctr@${hname}>"
@ idctr++
@ multipart++
goto anotherpart
endif
else
if ($outputfile == "") then
if (! $?to || ! $?subject || ! $?ctype || ! $?datafile) then
echo metasend: in batch mode, if output is not directed to a file,-t, -s, -f, and -m are all required
exit -1
endif
else
if (! $?datafile) then
echo metasend: in batch mode, -f is required.
endif
if ($isentity) then
if (! $?ctype) then
set ctype=bogus
# will not be used anyway really
endif
endif
if (! $?ctype ) then
echo metasend: in batch mode, with output directed to a file, -E or -m is required
exit -1
endif
endif
if (! -e $datafile) then
echo metasend: The file $datafile does not exist
exit -1
endif
# if (! $?cc) set cc=""
# if ($ctype != $ctyperaw) echo Double quotes not allowed, using $ctype
if (! $?encode) then
if ("$ctype" =~ text*) then
set encodingprog = "mimencode -q"
set encode = "quoted-printable"
else
set encodingprog = "mimencode -b"
set encode = base64
endif
else if ($encode == "base64") then
set encodingprog = "mimencode -b"
else if ($encode == "x-uue") then
set encodingprog = "uuencode mail-body"
else if ($encode == "7bit") then
set encodingprog = cat
else
set encodingprog = "mimencode -q"
set encode = "quoted-printable"
endif
endif
if (! $?encode) then
if ("$ctype" =~ text*) then
set encode = "quoted-printable"
set encodingprog = "mimencode -q"
else
set encode = base64
set encodingprog = "mimencode -b"
endif
endif
set ctype${multipart} = "$ctype"
set datafile${multipart} = $datafile
set encode${multipart} = $encode
set cdescrip${multipart} = "$cdescrip"
set cid${multipart} = "$cid"
set isentity${multipart} = $isentity
set encodingprog${multipart} = "$encodingprog"
set fname = ${METAMAIL_TMPDIR}/metasend.$$
echo "MIME-Version: 1.0" > $fname
if ($?to) then
echo "To: " "$to" >> $fname
endif
if ($?subject) then
echo "Subject: " "$subject" >> $fname
endif
if ($?cc) then
echo "CC: " "$cc" >> $fname
endif
if ($?from) then
echo "From: " "$from" >> $fname
endif
if ($multipart > 1) then
set boundary = ${hname}.$$.`date | tr " " .`
set newid=`date | tr " :" "__"`
if ($?multicid) then
echo "Content-ID: $multicid" >> $fname
else
echo "Content-ID: <${newid}_$idctr@${hname}>" >> $fname
@ idctr++
endif
echo "Content-type: multipart/$multipartsubtype;" >> $fname
echo " boundary="\"$boundary\" >> $fname
echo "" >> $fname
if ($?preamblefile) then
cat $preamblefile >> $fname
else
echo "This is a multimedia message in MIME format. If you are reading this" >> $fname
echo "prefix, your mail reader does not understand MIME. You may wish" >> $fname
echo "to look into upgrading to a newer version of your mail reader." >> $fname
endif
set i=1
set junkfile=${METAMAIL_TMPDIR}/mmjunk.$$
while ($multipart >= $i)
echo "" >> $fname
echo --$boundary >> $fname
echo set isentity=\$isentity$i > $junkfile
source $junkfile
if (! $isentity) then
echo -n "Content-ID: " >> $fname
echo echo \$cid$i \>\> $fname > $junkfile
source $junkfile
echo -n "Content-type: ">>$fname
echo echo \$ctype$i \>\> $fname > $junkfile
source $junkfile
echo -n "Content-Description: ">>$fname
echo echo \"\$cdescrip$i \" \>\> $fname > $junkfile
source $junkfile
echo -n "Content-Transfer-Encoding: " >>$fname
echo echo \$encode$i \>\> $fname > $junkfile
source $junkfile
echo "" >> $fname
endif
echo \$encodingprog$i \< \$datafile$i \>\> $fname > $junkfile
source $junkfile
@ i++
end
rm $junkfile
echo "" >> $fname
echo --${boundary}-- >> $fname
echo "" >> $fname
else
if (! $isentity) then
echo "Content-ID: $cid" >> $fname
echo "Content-type: " $ctype >> $fname
echo "Content-Description: " $cdescrip >> $fname
echo "Content-Transfer-Encoding: " $encode >> $fname
endif
echo "" >> $fname
$encodingprog < $datafile >> $fname
# Ensure last line has trailing carriage return
echo "" >> $fname
endif
if ($outputfile == "") then
if ($batchmode == 0) echo -n "Delivering mail, please wait... "
splitmail -s $splitsize -d $fname
if (! $status) then
if ($batchmode == 0) echo "Mail delivery apparently succeeded."
rm $fname
else if ($MustDelete == 1) then
echo Mail delivery failed
rm $fname
exit -1
else
echo Mail delivery failed, draft mail is in $fname
exit -1
endif
else
mv $fname $outputfile
if ($status) exit -1
endif
exit 0
METASEND MAN PAGE:
------------------------------
.TH metasend 1 "Release 1"
.SH NAME
metasend - Crude interface for sending non-text mail
.SH SYNOPSIS
.ta 8n
\fBmetasend\fP [-b] [-c cc] [-F from] [-e encoding] [-f filename] [-m MIME-type] [-s subject] [-S splitsize] [-t to] [-z] [-n] [-D content-description] [-o outputfile] [-/ multipart-subtype] [-E] [-P preamble-file]
.br
.SH DESCRIPTION
The
.I metasend
program will allow a user to send one or more pre-existing data file as non-text multimedia mail.
With no arguments, the program will ask the user for the To, Subject, and CC fields. It will then ask for the name of a MIME content-type. Next, it will ask the user for the name of an existing file containing that type of data. After this, it will ask what encoding type, if any, should be applied to this data. Finally, it will ask if the user wants to include information from an additional file, in which case the last three questions will be repeated for the next file.
Alternately, all of this information can be provided on the comand line, using the following options:
-b -- specifies Batch (non-interactive) Mode. Will exit with an error message if all additional needed information is not provided on the command line.
-c cc -- specifies the CC address
-D description -- specifies a string to be used as the Content-description value
-e encoding -- specifies the encoding type. Must be either "base64", "quoted-printable", "7bit", or "x-uue". "7bit" means no encoding is performed.
-E -- specifies that the file being included is already a full MIME entity, and does not need to have any Content-* or other header fields added.
-f filename -- specifies the file containing the data
-F from -- specifies the From address
-i "<content-id> -- specifies the content-id value for the MIME entity. Must be a legal content-id value, enclosed in angle brackets.
-I "<content-id>" -- specifies the content-id for the multipart entity being created by metasend, if any. Must be a legal content-id value, enclosed in angle brackets.
-m MIME-type -- specifies the MIME content-type
-n -- specifies that an additional file is to be included. Before each use of the -n option on the command line, the options -m, -c, and -f, at a minimum, must have appeared,and must appear separately for each included file.
-o outputfile -- specifies that the output from metasend should go to a named file rather than be delivered as mail.
-P preamblefile -- specifies a file containing alternative text to be put in the "preamble" area of a MIME multipart message.
-s subject -- specifies the Subject field
-S splitsize -- specifies the maximum size before splitting into parts via splitmail(1).
-t to -- specifies the To address
-z -- specifies that the temporary files should be deleted EVEN IF DELIVERY FAILS.
-/ subtype -- specifies the use of a MIME multipart subtype other than "mixed".
This is intended largely for mail hackers. A much friendlier interface to non-text mail is provided by mailto(1).
If more than one file is given, the parts will be combined into a single multipart MIME object.
The mail will be delivered using the splitmail(1) program, so if it is very long it will arrive as several pieces which can be automatically reassembled by metamail. The definition of "very long" can be altered using the -S flag or the SPLITSIZE environment variable, as described in the splitmail(1) man page.
.SH SEE ALSO
audiosend(1), mailto-hebrew(1), mailto(1), metamail(1), mmencode(1), splitmail(1)
.SH BUGS
Should do a better job of choosing the encoding if you don't specify one.
Should do MIME syntax checking on user-supplied content-type fields. Users are all too likely to provide bogus MIME content-type values, alas. In particular, there are various characters that are not allowed in parameters unless the parameters are enclosed in double quotes, but this sort of restriction is hard to enforce in a shell script!
.SH COPYRIGHT
Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
Permission to use, copy, modify, and distribute this material
for any purpose and without fee is hereby granted, provided
that the above copyright notice and this permission notice
appear in all copies, and that the name of Bellcore not be
used in advertising or publicity pertaining to this
material without the specific, prior written permission
of an authorized representative of Bellcore. BELLCORE
MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS",
WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
.SH AUTHOR
Nathaniel S. Borenstein, Bellcore
=======================================================================
From: Seth Rothenberg SROTHENB@montefiore.org
We use PERL for scripting, and we have installed
the Net::Mail module(s) for Perl.
I am attaching a script we use.
There is a lot of our applications glue
in the code, but it will help you see
how easy it is.
Notice how we must change the From: address,
because our unix does not get mail through
the Firewall. We want bounce messages to go to
an authentic user.
PERL SCRIPT:
------------------
#!/usr/bin/perl -w
require "ctime.pl";
use MIME::Entity;
# load parameters
# sample run: "email E2KCHG ./ batchout.dat batchout.return"
$|=1;
$logical = shift; # logical name of the client
$logical =~ s/_//; # get rid of "_" from the logical name
$logical = substr($logical,0,6);
shift; # External directory
$wkdir = shift; # Working directory
$fname = shift; # File name to be sent up
$rname = shift; # File name of return file
shift; # MAX_JOB_CMPL_TEST
shift; # EST_TIME_FIBMJOB
shift; # LRECL
shift; # BLKSIZE
shift; # HOST
shift; # USERID
shift; # PASSWD
$from = shift;
$to = shift;
$subject=shift;
$msg =shift;
$retval = -1;
chdir $wkdir || die "Cannot change to $wkdir:$!\n";
open(STDERR,">&STDOUT") || die "Could not open stderr\n";
$Date = &ctime(time);
print "\n\n script starting...$Date\n";
print "LOGICAL name which is after substr < $logical>\n";
# reset return file
open(RETURN, "> $rname");
print RETURN "-1";
close RETURN;
if (-z $fname)
{
print "$fname exists but it is an empty file\n";
open(FNAME, ">$fname") || die "Cannot open $fname:$!\n";
print FNAME "\n";
close FNAME;
}
print "Using Logical Name $logical\n";
#the mail program of choice
$mailprog = '/usr/lib/sendmail';
#who the mail is from ,to ,and the subject of this message
#$from = 'DATAGATE INTERFACE ENGINE <jzhang@monte.org>';
#$to = 'ngalland@monte.org,jzhang@smtp';
#$to = 'jzhang@smtp';
#$subject = 'batchout test';
#file to attach
$text_attach = $fname;
print "filename=$fname\n";
#text to replace at the end of the message
#$msg = 'DataGate mail test.';
#create the object ,and set up the mail headers:
$message = MIME::Entity->build(
Type =>"multipart/mixed",
-From => "$from",
-To => "$to",
-Subject =>"$subject");
attach $message Data=>$msg;
#attach #1
attach $message Path =>"$text_attach";
#Send it!
open(MAIL,"|$mailprog -t $to")
or die("mail open $mailprog error: $!");
#$message->send(\*MAIL);
$message->print(\*MAIL);
close(MAIL);
$retval=0;
print "putting $retval into $rname\n";
open(RETURN, "> $rname");
print RETURN $retval;
close RETURN;
exit $retval;
======================================================================
THANKS TO:
Alina Runde ARunde@mms.com
Rich Kulawiec rsk@gsp.org
Jeff Wasilko jeffw@smoe.org
Tim Carlson tim@santafe.edu
Jay Lessert jay_lessert@latticesemi.com
Mark Bergman bergman@phri.nyu.edu
Andrew F. Maddox amaddox@usgen.com
Virginia Coffindaffer Virginia.Coffindaffer@wang.com
Dave Plummer dlp@medphys.ucl.ac.uk
Bill Hathaway wdh@poss.com
Bismark Espinoza bismark@alta.Jpl.Nasa.Gov
Thomas Anders anders@hmi.de
Derek Terveer derek.terveer@ci.saint-paul.mn.us
Greg Ackerson ackerson_ga@nns.com
Seth Rothenberg SROTHENB@montefiore.org
Jim Harmon jharmon@telecnnct.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Esther Muller
Unix System Administrator
Xcel Engineering & Management
Cel : 083 454 6117
Tel(w) : 27-12-3199405
Fax : 27-12-3219622
E-mail (w) : emr@wcomp.gov.za
E-mail (h) : esther@pixie.co.za
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:41 CDT