[svlug] smtp and mime from scripts?

Seth David Schoen schoen at loyalty.org
Wed Aug 9 19:38:02 PDT 2000


Greg Herlein writes:

> I'm trying to send an email from a bash script (actually, the
> faxrcvd script in hylafax) and want to include a jpeg file as an
> attachment.  The example I am working from uses a postscript file
> - which is included by simply redirecting the conversion program
> right to stdout - which works since the output is postscript
> (text).
> 
> Unfortunatley, the conversion program for jpeg files yeilds a
> binary.
> 
> I've hunted, I've read rfc's, I've web searched on all the
> keywords I can think of - and I cannot find out how to include a
> binary attachment in an email generated from a script directly to
> an smtp agent.
> 
> Can someone send me a pointer, or better yet, an example script?

There are examples which call perl or python scripts, even one-liners,
and maybe some using metasend or other command-line equivalents.

You can also send using "mutt -a", which someone recommended on a list
and which worked like a charm.  Of course, mutt will need to run a
local sendmail or whatever it's configured to use to send the mail on,
but it will handle the MIME stuff for you properly.

You can, for example

echo 'Message body' | mutt -s 'Subject line' -a file.jpeg user at host

and it should work beautifully.  Better yet, you can use multiple -a
switches to attach multiple files to a single message.

If you really need to speak SMTP right in the script, you have a much
trickier problem, but I guess look at mimencode(1) or the Perl and
Python MIME stuff.

-- 
Seth David Schoen <schoen at loyalty.org>  | And do not say, I will study when I
Temp.  http://www.loyalty.org/~schoen/  | have leisure; for perhaps you will
down:  http://www.loyalty.org/   (CAF)  | not have leisure.  -- Pirke Avot 2:5




More information about the svlug mailing list