This page outlines several methods of generating email
messages from command line and shell scripts using both
popular email processing tools such as metamail and mpack,
and home grown scripts. Most of these methods use the MIME
specification, as outlined in
RFC 2045,
RFC 2046,
RFC 2047,
RFC 2048 and
RFC 2049.
Please send
mail to me with any comments, suggestions, criticism or
additions.
All of the below examples use the following shell variables.
I use MIME type application/octet-stream just as an example.
Actual type used will vary depending upon attachment file
type. Remember, these are simple examples of the different
tools available.
TXTFILE=/tmp/textfile # A text message with a simple preface message ATTFILE=/tmp/binary_file # File to be attached and generally requiring encoding SUBJECT="Your attachment" # Change as needed [email protected] # Ditto
uuencode $ATTFILE $ATTFILE | mail -s "$SUBJECT" $MAILTO (uuencode $FILE1 $FILE1; uuencode $FILE2 $FILE2) | mail -s "$SUBJECT" $MAILTO
echo "From: $LOGNAME\nTo: $MAILTO\nSubject: $SUBJECT\n\ Mime-Version: 1.0\nContent-Type: text/plain\n" > /tmp/file cat $TXTFILE >> /tmp/file /usr/lib/sendmail -t -oi < /tmp/file
metasend -b -s "$SUBJECT" -f $TXTFILE -m text/plain -e none -n \ -f $ATTFILE -m application/octet-stream -e base64 -t $MAILTO
mpack -s "$SUBJECT" -c application/octet-stream $ATTFILE $MAILTO
mutt -a $ATTFILE -s "$SUBJECT" $MAILTO < $TXTFILE
elm -s"$SUBJECT" -A $ATTFILE $MAILTO < $TXTFILEOlder versions of elm without ME+ won't even deal with attachments at all, detaching or attaching.
uuenview -m $MAILTO -b -a $ATTFILE < $TXTFILE
nail -s "$SUBJECT" -a $ATTFILE $MAILTO < $TXTFILE
For a single file: cat $TXTFILE | zmail.small -subject "$SUBJECT" -attach \ application/octet-stream:${ATTFILE} $MAILTO Bart Schaefer offers the following for multiple attachments. (untested by myself) zmail.small -rf /dev/null -e 'mail -z -s "$SUBJECT" $MAILTO' \ -e 'compcmd attach-file $ATTACHFILE application/msword base64 \ "$DESCRIPTION"' \ -e! 'compcmd send' You can repeat the -e 'compcmd attach-file ...' as often as necessary to attach more than one file. The -z in the mail command tells it not to go interactive, but rather to wait for compcmds to tell it what to do.
Here is some
Bourne shell code (taken out of a
deliver enabled autoresponder) for creating email
messages with multiple attachments of varying types. This
script uses metamail's mmencode program for encoding
and sendmail for sending.
Check out this far more advanced
shell script written by Dave Wotton that does much more
than my simple script. It uses a encoder called encdec
that I am not familiar with but will soon address on this
page. In the meantime, you could use mmencode
mentioned previously for the encoding.
And here is some basic, fairly static
Perl code using the MIME::Lite module to send an
attachment along with a text note to a sender. This is
almost verbatim from the modules man page and could use some
tweaking to get it more useful but it certainly works as a "plugin"
piece of code.
Here is a
useful page by Heiner Steven with several examples of
shell coding using metamail and mpack in particular.
For an excellent guide to creating proper text files and for
the formatting of your message if you write your own script,
please see Keith Moore's
style guide.
freshmeat.net Project details for MHonArc
MHonArc is a Perl program for converting mail or news messages into HTML archives. It can also be used to convert individual messages into HTML documents. Other capabilities include robust MIME support and powerful user customization features.
freshmeat.net Project details for ripMIME
ripMIME extracts attachment files out of a MIME-encoded email pack.
Author:
Paul L Daniels
[contact developer]
|
Homepage:
http://www.pldaniels.com/ripmime/
Tar/GZ:
http://www.pldaniels.com/ripmime/ripmime-1.4.0.7.tar.gz
Changelog:
http://www.pldaniels.com/ripmime/CHANGELOG
Trove categories: [change]
[Development Status] | 5 - Production/Stable | |
[Environment] | Console (Text Based) | |
[Intended Audience] | End Users/Desktop, System Administrators | |
[License] | OSI Approved :: BSD License (original), OSI Approved :: BSD License (revised) | |
[Operating System] | OS Independent | |
[Programming Language] | C | |
[Topic] | Communications :: Email, Communications :: Email :: Filters, Software Development :: Libraries |
Dependencies:
[change]
No dependencies filed