INFODOC ID: 18540 STATUS: Issued SYNOPSIS: How do I send MIME encoded messages from the command line? DETAIL DESCRIPTION: I want to send MIME encoded email via the command. How do I do that? There are no command line programs to do this in Solaris. There is a freeware product called Metamail from Bellcore that can do the job from the command line. It can be found at: ftp://thumper.bellcore.com:/pub/nsb/ Or you can use the following Bourne shell script. (This is not a supported script from Sun. It might work or it might not. Use at your own risk.) Read through the following script before executing. ~~~~~~~~~~~~~Begin Script~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!/bin/sh #**************************************************************************** #** Sun Microsystems Inc. ** #** File: mail_file ** #** Type: Bourne Shell ** #** Purpose: Command used to send an email, passing the named file as ** #** an OWN V3 Mailtool "Attachment". ** #** ** #** This file takes the following 4 parameters: ** #** ** #** 1 - TO (ex: joe.jones@sybase.com) ** #** 2 - SUBJECT (ex: "Here's your file") ** #** 3 - MESSAGE_FILE (ex: /tmp/message_file) ** #** 4 - ATTACH_FILE (ex: /tmp/attach_file) ** #** ** #**************************************************************************** TO=$1 SUBJECT=$2 MESSAGE_FILE=$3 ATTACH_FILE=$4 #--------------------------------------------------------------------- # Function: build_header_text() # Description: Creates a "Text" attachment out of the passed MESSAGE file. # Returns: Sets $TotalLines to the total number of lines so far, # and cat's the header text into /tmp/$$-x. #--------------------------------------------------------------------- build_header_text () { # Get the text message length, etc. LinesValue=`wc -l $MESSAGE_FILE | nawk '{ print $1 }'` LengthValue=`wc -c $MESSAGE_FILE | nawk '{ print $1 }'` TotalLines=`echo "$LinesValue 5 + p" | dc` TotalLength=LengthValue # Copy the correct header information into the output file echo "----------" >> /tmp/$$-x echo "X-Sun-Data-Type: text" >> /tmp/$$-x echo "X-Sun-Data-Description: text" >> /tmp/$$-x echo "X-Sun-Data-Name: text" >> /tmp/$$-x echo "X-Sun-Content-Lines: "$LinesValue >> /tmp/$$-x echo "X-Sun-Content-Length: "$LengthValue >> /tmp/$$-x echo "" >> /tmp/$$-x cat $MESSAGE_FILE >> /tmp/$$-x echo "----------" >> /tmp/$$-x } # end build_header_text #--------------------------------------------------------------------- # Function: determine_file_type() # Description: Figures out whether this is a Postscript, Cshell, # Bourne shell, or Text file. # Returns: Sets $FileType to a value suitable for using in the # header of an Attachment. #--------------------------------------------------------------------- determine_file_type () { # Get the first line of the Attachment file FirstLine=`cat $ATTACH_FILE | nawk '{ if (NR == 1) print $1, $2; }'` # Determine the type of file it is if echo $FirstLine | grep "PS" > /dev/null then FileType="postscript-file" elif echo $FirstLine | grep "/bin/csh" > /dev/null then FileType="cshell-script" elif echo $FirstLine | grep "/bin/sh" > /dev/null then FileType="shell-script" else FileType="text" fi } # end determine_file_type #--------------------------------------------------------------------- # Function: append_file() # Description: Appends file to end of work file. # Returns: Increments $TotalLines by the number of lines in file. # Appends file itself to /tmp/$$-x. #--------------------------------------------------------------------- append_file () { determine_file_type LinesValue=`wc -l $ATTACH_FILE | nawk '{ print $1 }'` LengthValue=`wc -c $ATTACH_FILE | nawk '{ print $1 }'` TotalLines=`echo "$TotalLines $LinesValue + p" | dc` SHORTNAME=`basename $ATTACH_FILE`; export SHORTNAME echo "X-Sun-Data-Type: $FileType" >> /tmp/$$-x echo "X-Sun-Data-Name: "$SHORTNAME >> /tmp/$$-x echo "X-Sun-Content-Lines: "$LinesValue >> /tmp/$$-x echo "X-Sun-Content-Length: "$LengthValue >> /tmp/$$-x echo "" >> /tmp/$$-x cat $ATTACH_FILE >> /tmp/$$-x } #--------------------------------------------------------------------- # Function: assemble_enchilada() # Description: Builds a file from the subject lines, total # length, and concatenated attachments. # Returns: Creates /tmp/$$-outbound file. #--------------------------------------------------------------------- assemble_enchilada () { echo "To: " $TO > /tmp/$$-outbound echo "Subject: "$SUBJECT >> /tmp/$$-outbound echo "Content-Type: X-sun-attachment" >> /tmp/$$-outbound echo "X-Lines: "$TotalLines >> /tmp/$$-outbound echo "" >> /tmp/$$-outbound cat /tmp/$$-x >> /tmp/$$-outbound } #--------------------------------------------------------------------- # Main program execution #--------------------------------------------------------------------- build_header_text append_file assemble_enchilada cat /tmp/$$-outbound | /usr/lib/sendmail -t rm -f /tmp/$$-* ~~~~~~~~~~End Script~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTERNAL SUMMARY: Sendmail 8.8.8 from SUN has some MIME capable features, but in general cannot "make" MIME messages to be sent out. File name as of 2 Mar 99 is -> mm2.7.tar.Z SUBMITTER: SWATANAB, Mar 16 1999 9:55AM PRODUCT AREA: Gen. Network PRODUCT: Mail SUNOS RELEASE: n/a HARDWARE: n/a