#!/usr/bin/perl use strict; use warnings; use MIME::Base64; my $SENDFILE = 'z.jpg'; my $FROMUSER = 'zentara'; my $FROMEMAIL = 'zentara@zentara.zentara.net'; my $TOUSER = 'zentara'; my $TOEMAIL = 'zentara@zentara.zentara.net'; open(F_MAIL,"|/usr/sbin/sendmail -t"); my $boundary = "----------90125"; print F_MAIL < To: $TOUSER <$TOEMAIL> MIME-Version: 1.0 Subject: File attachment test Content-Type: multipart/mixed; boundary=\"$boundary\" This is a multi-part message in MIME format. --$boundary Content-Type: text/plain; charset=\"iso-8859-1\" Here is the body of the message. A file attachment is also provided below. --$boundary Content-Type: application/octet-stream; name=\"$SENDFILE\" Content-Transfer-Encoding: Base64 Content-Disposition: attachment; filename=\"$SENDFILE\" END_OF_MAIL #open(F_SEND,$SENDFILE) || &Error("Cannot open sendfile for MIME encoding"); open(F_SEND,$SENDFILE) || die ("Cannot open sendfile for MIME encoding"); while (read(F_SEND,my $buf, 60 * 57 ) ) { print F_MAIL encode_base64($buf); } close(F_SEND); print F_MAIL <## #!/usr/bin/perl use warnings; use strict; use MIME::Lite; $MIME::Lite::AUTO_CONTENT_TYPE="true"; my $msg = MIME::Lite->new( From => 'zentara' , To => 'zentara@z.net' , Subject => 'test attach', Type => 'multipart/mixed' ); $msg->attach( Path => './mailbody' , Filename => 'message.txt' ); $msg->attach( Path => "./logfile_07-24-2005.tar.gz" , Disposition => "attachment" ); $msg->send; print "Mission accomplished\n"; __END__