use Net::SMTP; use strict; use warnings; use MIME::Base64 qw( encode_base64 ); print "Content-type: text/html\n\n"; print "\n
\n\n\n"; my $from = 'tester@mydomain.com'; my $to = 'myalias@mydomain.com'; my $attachBinaryFileName = 'test.jpg'; my $attachTextFileName = 'testattach.txt'; my $boundary = 'frontier'; my $smtp = Net::SMTP->new('mail.mydomain.com', Timeout => 10) || die("Could not create SMTP object."); $smtp->mail($from); $smtp->recipient($to, { SkipBad => 1 }); $smtp->data(); $smtp->datasend("To: $to\n"); $smtp->datasend("From: $from\n"); $smtp->datasend("Subject: Multi part test\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundary\"\n"); #$smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-type: text/plain\n"); $smtp->datasend("Content-Disposition: quoted-printable\n"); $smtp->datasend("\nToday\'s files are attached:\n"); $smtp->datasend("\nHave a nice day! :)\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-Type: application/text; name=\"$attachTextFileName\"\n"); $smtp->datasend("Content-Disposition: attachment; filename=\"$attachTextFileName\"\n"); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-Type: image/jpeg; name=\"$attachBinaryFileName\"\n"); $smtp->datasend("Content-Transfer-Encoding: base64\n"); $smtp->datasend("Content-Disposition: attachment; filename=\"$attachBinaryFileName\"\n"); $smtp->datasend("\n"); my $buf; open(DAT, "$attachBinaryFileName") || die("Could not open binary file!"); binmode(DAT); local $/=undef; while (read(DAT, my $binaryfile, 114)) { $buf = &encode_base64( $binaryfile ); $smtp->datasend($buf); } close(DAT); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->dataend(); $smtp->quit; ####