#!/usr/bin/perl use MIME::Base64 qw(encode_base64); use Net::SMTP; # thisprog.pl name@address.com me@here.com subject email attachfile sendemail(@ARGV); sub sendemail(){ ($email, $from, $subject, $emailtext,$filename) = @_; $smtp = Net::SMTP->new('mail.im-passe.com',Debug=>1); $smtp->mail('outgoing@im-passe.com'); $smtp->to($email); $smtp->data(); $smtp->datasend("From: \"$from\" <$from>\n"); $smtp->datasend("To: \"$email\" <$email>\n"); $smtp->datasend("Subject: $subject\n"); $date = localtime(); $smtp->datasend("Date: $date\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-Type: multipart/mixed;\n"); $smtp->datasend(" boundary=\"-----=_MOOF_000_0009_01C204C8.B926E720\"\n"); $smtp->datasend("X-Priority: 3\n"); $smtp->datasend("X-MSMail-Priority: Normal\n"); $smtp->datasend("X-Mailer: Mike Davis's little perl script\n"); $smtp->datasend("\n"); $smtp->datasend("This is a multi-part message in MIME format.\n"); $smtp->datasend("\n"); $smtp->datasend("------=_MOOF_000_0009_01C204C8.B926E720\n"); $smtp->datasend("Content-Type: text/plain;\n"); $smtp->datasend(" charset=\"iso-8859-1\"\n"); $smtp->datasend("Content-Transfer-Encoding: 7bit\n"); $smtp->datasend("\n"); #email text content here if($filename){ $smtp->datasend("\n"); $smtp->datasend("------=_MOOF_000_0009_01C204C8.B926E720\n"); $smtp->datasend("Content-Type: application/octet-stream;\n"); $smtp->datasend(" name=\"$filename\"\n"); $smtp->datasend("Content-Transfer-Encoding: base64\n"); $smtp->datasend("Content-Disposition: attachment;\n"); $smtp->datasend(" filename=\"$filename\"\n"); $smtp->datasend("\n"); open(FILE, $filename)or die "$!"; while (read(FILE, $buf, 60*57)) { $smtp->datasend(encode_base64($buf)); } close(FILE); } $smtp->datasend("\n"); $smtp->datasend("------=_MOOF_000_0009_01C204C8.B926E720--\n"); $smtp->dataend(); $smtp->quit; }