[thelist] shell script problem

Dean Mah dmah at shaw.ca
Thu Mar 20 09:19:17 CST 2003


On Thu, Mar 20, 2003 at 08:00:36PM +0700, Rob Schumann wrote:

> The first parts are no problem, but the emailing bit has me stumped. Is
> there some way for a shell script to communicate directly (or indirectly
> come to that) with sendmail??

The simpliest would be:

#!/bin/sh

/usr/sbin/sendmail -t <<EOF
To: you at yourhost.ca
From: me at myhost.ca
Subject: Test

This is it.
EOF


> My guess is that I would have to manually assemble the mail headers
> within the shell script, adding the attachment and then pass this on
> to sendmail for despatch.

You would have to assemble the MIME headers and encode your attachment
appropriately, likely Base64 encoding.  For the headers you would need:

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="myrandomboundarystring"

Then each part of the message you need to set up your content type and
encoding.  For text parts you would have something like:

--myrandomboundarystring
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


For binary parts that are Base64 encoded you would have something like:

--myrandomboundarystring
Content-Type: application/x-zip-compressed; name="myfile.zip"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="myfile.zip"


And then you end it all with:

--myrandomboundarystring--


> Does anyone have a readymade solution for this... or some pointers
> to how to do it/where to find the answers.

I have Perl scripts that will mail attachments but not shell ones.
However, check your machine to see if you have 'sendfiles' which might
do exactly what you want without all the hassle.  Or do 'man -k mime'
and see what comes up.

Dean


More information about the thelist mailing list