This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.
Subject: Re: mail commands & script From: "Anthony E. Greene" <agreene@pobox.com> Date: Sun, 23 May 1999 19:42:24 +0200 (CEST) On Sun, 23 May 1999, Greg W wrote: >If anyone has a working script that attaches a file and mails ok from >command line and does not mind giving it up it would be much appreciated (i >may be missing uuencode function as well, cant get to attach properly) The easiest way requires uuencode to be available: uuencode file.ext file.ext | mail -s file.ext user@domain Most mail clients will correctly decode the file and treat it as an attachment. An alternative would be to use mimencode and make sure to create all the necessary MIME info in the headers and body: sendfile myfile user@domain | /sbin/sendmail -t 'sendfile' is a shell script as shown below. There's no error checking, but it works on my system. You may need to verify the pathnames. *************cut here*************************** #!/bin/bash # # Script: sendfile # # Purpose: Send the specified file via email as a MIME # attachment to the specified address. # # Author: Anthony E. Greene <agreene@pobox.com> # # License: GPL <http://www.gnu.org/> # # Note: This script does not include any error checking, so # it should only be called from within other scripts. # The correct syntax for using this script is: # # sendfile filename user@domain | /path/to/sendmail -t # # First we set up some global variables. # Some code should be added to verify the commandline arguments. sender=agreene@pobox.com filename=$1 basefile=`/bin/basename $filename` recipient=$2 echo From: $sender echo To: $recipient echo Subject: File $basefile echo MIME-Version: 1.0 echo "Content-Type: multipart/mixed; Boundary=\"sendfile-attachment-boundary\"" echo echo --sendfile-attachment-boundary echo 'Content-Type: text/plain; charset=us-ascii' echo echo This is a MIME encoded message. If your mail software echo cannot properly handle the attached file, you may need echo to get a MIME-aware mailer. echo echo --sendfile-attachment-boundary echo "Content-Type: application/octet-stream; name=\"$basefile\"" echo Content-Transfer-Encoding: base64 echo "Content-Disposition: attachment; filename=\"$basefile\"" echo /usr/bin/mimencode $filename echo --sendfile-attachment-boundary-- *************cut here*************************** ===