mail (a bit ot)
Paul Richards
paul at freebsd-services.co.uk
Fri Apr 13 14:12:20 BST 2001
--On Tuesday, April 10, 2001 22:27:01 +0100 Ian MacDonald <ian at macware.net>
wrote:
> Try something like:
>
> gzip -c <FILENAME> |uuencode <FILENAME>.gz |mail -s "SUBJECT"
> SOMEONE at SOMEWHERE.CO.UK
That'd work but you'd probably be better off using MIME these days, it's
not too difficult to construct a valid mime message.
This perl snippet might work but I wrote it in the mail message so it's not
tested :-)
my $file = "the file you want to be gzipped";
my $MMENCODE = "/usr/local/bin/mmencode";
my $SENDMAIL = "/usr/sbin/sendmail";
my $USER = "someone at somewhere.com";
my $BOUNDARY = "attachment";
my $MSG = "A gzip file, $file is attached";
if (! open(SENDMAIL, "| $SENDMAIL $USER")) {
print STDERR "Couldn't create pipe, $SENDMAIL $USER, $!\n";
} else {
print SENDMAIL "To: $USER\n";
print SENDMAIL "Subject: Here's your gzipped files \n";
print SENDMAIL "Mime-Version: 1.0\n";
print SENDMAIL "Content-Type: multipart/mixed; ";
print SENDMAIL "boundary=\"$BOUNDARY\"\n";
print SENDMAIL "\n\n";
print SENDMAIL "--$BOUNDARY\n";
print SENDMAIL "Content-Type: text/plain; charset=us-ascii\n";
print SENDMAIL "\n";
print SENDMAIL "$MSG\n";
print SENDMAIL "--$BOUNDARY\n";
print SENDMAIL "Content-Type: application/octet-stream\n";
print SENDMAIL "Content-Transfer-Encoding: base64\n";
print SENDMAIL "\n";
print SENDMAIL `$GZIP "$file"`;
# BASE64 Encode it and include it in the message
print SENDMAIL `$MMENCODE "$file"`;
print SENDMAIL "\n--$BOUNDARY--";
if (! close(SENDMAIL)) {
print STDERR "Couldn't close pipe, $SENDMAIL $USER, $!\n";
}
}
I'm not certain that application/octet-stream is the most appropriate for
attaching gzip files but I don't have a complete mime types file around to
see if there's something better.
It should be easy enough to convert that to a shell script if you need to.
Paul.
More information about the Ukfreebsd
mailing list